Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementacija - Administracija Dnevnika Stručne Prakse #2

Open
wants to merge 2 commits into
base: grupa2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ePraksa/.vs/e-StrucnaPraksa/config/applicationhost.config
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
</site>
<site name="e-StrucnaPraksa" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\Marin\Firma\ePraksa" />
<virtualDirectory path="/" physicalPath="C:\Users\tbozi\Desktop\ePraksa2021\ePraksa" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:4993:localhost" />
Expand Down
Binary file added ePraksa/.vs/e-StrucnaPraksa/v16/.suo
Binary file not shown.
129 changes: 129 additions & 0 deletions ePraksa/Controllers/StudentDnevnikController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System.Web.Mvc;
using PracticeManagement.Core;
using PracticeManagement.Core.Models;
using PracticeManagement.Core.ViewModel;

namespace PracticeManagement.Controllers
{
[Authorize]
public class StudentDnevnikController : Controller
{
private readonly IUnitOfWork _unitOfWork;
public StudentDnevnikController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}

[Authorize(Roles = RoleName.MentorRoleName + "," + RoleName.ProfesorRoleName + "," + RoleName.StudentRoleName)]
public ActionResult Index(int praksaId)
{
var StudentDnevnik = _unitOfWork.StudentDnevniks.GetStudentDnevniks(praksaId);
var model = new StudentDnevnikIndexViewModel{ StudentDnevniks = StudentDnevnik, praksaId = praksaId };
return View(model);
}

[Authorize(Roles = RoleName.StudentRoleName)]
public ActionResult Create(int praksaId)
{
var viewModel = new StudentDnevnikFormViewModel
{
StudentDnevniks = _unitOfWork.StudentDnevniks.GetStudentDnevniks(praksaId),
Heading = "New Student",
studentPraksaId = praksaId,
};
return View("StudentDnevnikForm", viewModel);
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(StudentDnevnikFormViewModel viewModel)
{
if (!ModelState.IsValid)
{
viewModel.StudentDnevniks = _unitOfWork.StudentDnevniks.GetStudentDnevniks(viewModel.studentPraksaId);
return View("StudentDnevnikFormViewModel", viewModel);

}

var studentDnevnik = new StudentDnevnik
{
studentPraksaId = viewModel.studentPraksaId,
datum = System.DateTime.Now,
aktivnost = viewModel.aktivnost,
linkovi = viewModel.linkovi,
dodatno = viewModel.dodatno,
komentar = viewModel.komentar
};

_unitOfWork.StudentDnevniks.Add(studentDnevnik);
_unitOfWork.Complete();
return RedirectToAction("Index", "StudentDnevnik", new { praksaId = viewModel.studentPraksaId });
}

[Authorize(Roles = RoleName.MentorRoleName + "," + RoleName.StudentRoleName)]
public ActionResult Edit(int id)
{
var StudentDnevnik = _unitOfWork.StudentDnevniks.GetStudentDnevnik(id);
if (StudentDnevnik == null) return HttpNotFound();

var viewModel = new StudentDnevnikFormViewModel()
{
studentPraksaId = StudentDnevnik.studentPraksaId,
aktivnost = StudentDnevnik.aktivnost,
linkovi = StudentDnevnik.linkovi,
dodatno = StudentDnevnik.dodatno,
komentar = StudentDnevnik.komentar
};
return View(viewModel);
}

[HttpPost]
public ActionResult Edit(StudentDnevnikFormViewModel viewModel)
{
if (!ModelState.IsValid)
{
viewModel.StudentDnevniks = _unitOfWork.StudentDnevniks.GetStudentDnevniks(viewModel.studentPraksaId);
return View("StudentDnevnikFormViewModel", viewModel);
}

var studentDnevnik = _unitOfWork.StudentDnevniks.GetStudentDnevnik(viewModel.Id);
studentDnevnik.aktivnost = viewModel.aktivnost;
studentDnevnik.linkovi = viewModel.linkovi;
studentDnevnik.dodatno = viewModel.dodatno;
studentDnevnik.komentar = viewModel.komentar;
_unitOfWork.Complete();

return RedirectToAction("Index", "StudentDnevnik", new { praksaId = viewModel.studentPraksaId });
}

[Authorize(Roles = RoleName.StudentRoleName)]
public ActionResult Delete(StudentDnevnik st)
{
_unitOfWork.StudentDnevniks.Delete(st.Id);
_unitOfWork.Complete();
return RedirectToAction("Index", "StudentDnevnik", new { praksaId = st.studentPraksaId });
}

[Authorize(Roles = RoleName.MentorRoleName)]
[HttpPost]
public ActionResult ToggleStatus(int id)
{
var studentDnevnik = _unitOfWork.StudentDnevniks.GetStudentDnevnik(id);
studentDnevnik.Odobreno = !studentDnevnik.Odobreno;
_unitOfWork.Complete();
return RedirectToAction("Index", "StudentDnevnik", new { praksaId = id });
}

[Authorize(Roles = RoleName.MentorRoleName + "," + RoleName.ProfesorRoleName + "," + RoleName.StudentRoleName)]
public ActionResult Details(int id)
{
var viewModel = new StudentDnevnikDetailViewModel()
{
studentDnevnik = _unitOfWork.StudentDnevniks.GetStudentDnevnik(id),
praksaId = id

};
return View("Details", viewModel);
}
}
}
5 changes: 4 additions & 1 deletion ePraksa/Core/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public interface IUnitOfWork
//IStudentRatingRepository StudentRatings { get; }
IFacultyCourseRepository FacultyCourses { get; }
//IMentorRepository Mentors { get; }

//IPollRepository Polls { get; }
// IPollQuestionRepository PollQuestions{ get; }

IStudentPraksaRepository StudentPraksas { get; }
IStudentDnevnikRepository StudentDnevniks { get; }
void Complete();
}
}
23 changes: 23 additions & 0 deletions ePraksa/Core/Models/StudentDnevnik.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace PracticeManagement.Core.Models
{
public class StudentDnevnik
{
public int Id { get; set; }

[ForeignKey("StudentPraksa")]
public int studentPraksaId { get; set; }
public bool Odobreno { get; set; }
public DateTime datum { get; set; }
public string aktivnost { get; set; }
public string linkovi { get; set; }
public string dodatno { get; set; }
public string komentar { get; set; }
public StudentPraksa StudentPraksa { get; set; }
}
}
31 changes: 31 additions & 0 deletions ePraksa/Core/Models/StudentPraksa.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace PracticeManagement.Core.Models
{
public class StudentPraksa
{
public int Id { get; set; }

[ForeignKey("Faculty")]
public int fakultetId { get; set; }

[ForeignKey("Firm")]
public int firmaId { get; set; }

[ForeignKey("Mentor")]
public int mentorId { get; set; }

[ForeignKey("Profesor")]
public int profesorId { get; set; }

[ForeignKey("Student")]
public int studentId { get; set; }

public Faculty Faculty { get; set; }
public Firm Firm { get; set; }
public Mentor Mentor { get; set; }
public Profesor Profesor { get; set; }
public Student Student { get; set; }

}
}
16 changes: 16 additions & 0 deletions ePraksa/Core/Repositories/IStudentDnevnikRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using PracticeManagement.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PracticeManagement.Core.Repositories
{
public interface IStudentDnevnikRepository
{
IEnumerable<StudentDnevnik> GetStudentDnevniks(int praksaId);
void Add(StudentDnevnik studentDnevnik);
void Delete(int id);
StudentDnevnik GetStudentDnevnik(int id);
}
}
13 changes: 13 additions & 0 deletions ePraksa/Core/Repositories/IStudentPraksaRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using PracticeManagement.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PracticeManagement.Core.Repositories
{
public interface IStudentPraksaRepository
{
IEnumerable<StudentPraksa> GetStudentPraksas();
}
}
14 changes: 14 additions & 0 deletions ePraksa/Core/ViewModel/StudentDnevnikDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using PracticeManagement.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PracticeManagement.Core.ViewModel
{
public class StudentDnevnikDetailViewModel
{
public StudentDnevnik studentDnevnik { get; set; }
public int praksaId { get; set; }
}
}
43 changes: 43 additions & 0 deletions ePraksa/Core/ViewModel/StudentDnevnikFormViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
using System.Web.Mvc;
using PracticeManagement.Controllers;
using PracticeManagement.Core.Helpers;
using PracticeManagement.Core.Models;

namespace PracticeManagement.Core.ViewModel
{
public class StudentDnevnikFormViewModel
{
public int Id { get; set; }
[Required]
public int studentPraksaId { get; set; }
[Required]
public DateTime datum { get; set; }
[Required]
public string aktivnost { get; set; }
[Required]
public string linkovi { get; set; }
[Required]
public string dodatno { get; set; }
public string komentar { get; set; }

public string Action
{
get
{
//Expression<Func<StudentDnevnikController, ActionResult>> update = (c => c.Update(this));
Expression<Func<StudentDnevnikController, ActionResult>> create = (c => c.Create(this));

var action = (Id != 0) ? null : create;
return (action.Body as MethodCallExpression).Method.Name;

}
}

public string Heading { get; internal set; }
public IEnumerable<StudentDnevnik> StudentDnevniks { get; internal set; }
}
}
15 changes: 15 additions & 0 deletions ePraksa/Core/ViewModel/StudentDnevnikIndexViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using PracticeManagement.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PracticeManagement.Core.ViewModel
{
public class StudentDnevnikIndexViewModel
{
public IEnumerable<StudentDnevnik> StudentDnevniks { get; set; }
public int praksaId { get; set; }

}
}
14 changes: 10 additions & 4 deletions ePraksa/Persistence/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public DbSet<Firm> Firms { get; set; }
public DbSet<Core.Models.FirmAddress> FirmAddresses { get; set; }
public DbSet<FirmType> FirmTypes { get; set; }

//public DbSet<Poll> Polls { get; set; }
// public DbSet<PollQuestion> PollQuestions { get; set; }


//public DbSet<Poll> Polls { get; set; }
// public DbSet<PollQuestion> PollQuestions { get; set; }

public DbSet<StudentPraksa> StudentPraksas { get; set; }
public DbSet<StudentDnevnik> StudentDnevniks { get; set; }

public ApplicationDbContext()
: base("StrucnaPraksa", throwIfV1Schema: false)
{
Expand Down Expand Up @@ -69,6 +72,9 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Configurations.Add(new FacultyCourseConfiguration());
modelBuilder.Configurations.Add(new YearOfStudyConfiguration());

modelBuilder.Configurations.Add(new StudentPraksaConfiguration());
modelBuilder.Configurations.Add(new StudentDnevnikConfiguration());

// modelBuilder.Entity<Faculty2>().ToTable("Faculties");
//modelBuilder.Configurations.Add(new PatientStatusConfiguration());
base.OnModelCreating(modelBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using PracticeManagement.Core.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Web;

namespace PracticeManagement.Persistence.EntityConfigurations
{
public class StudentDnevnikConfiguration: EntityTypeConfiguration<StudentDnevnik>
{
public StudentDnevnikConfiguration()
{
Property(p => p.Id).IsRequired();
Property(p => p.studentPraksaId).IsRequired();
Property(p => p.datum).IsRequired();
Property(p => p.aktivnost).IsRequired();
Property(p => p.linkovi).IsRequired();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using PracticeManagement.Core.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Web;

namespace PracticeManagement.Persistence.EntityConfigurations
{
public class StudentPraksaConfiguration: EntityTypeConfiguration<StudentPraksa>
{
public StudentPraksaConfiguration()
{
Property(p => p.Id).IsRequired();
Property(p => p.fakultetId).IsRequired();
Property(p => p.firmaId).IsRequired();
Property(p => p.mentorId).IsRequired();
Property(p => p.profesorId).IsRequired();
Property(p => p.studentId).IsRequired();
}
}
}
Loading