public IActionResult ChangeTaskState(int taskId, State State, float?EstimatedTime) { Task task = context.Tasks.Find(taskId); switch (State) { case State.Iniciada: task.State = State.Iniciada; task.StartDate = DateTime.Now; if (EstimatedTime != null) { task.EstimatedTime = (float)EstimatedTime; } break; case State.Finalizada: task.EndDate = DateTime.Now; TimeSpan diff = (task.EndDate - task.StartDate).Value; task.State = State.Finalizada; task.ActualTime = diff.Hours; break; case State.Detenida: task.State = State.Detenida; break; case State.Cancelada: task.State = State.Cancelada; break; } context.Update(task); context.SaveChanges(); return(RedirectToAction("Details", new { Id = taskId })); }
public IActionResult Create(UserViewModel user) { if (ModelState.IsValid) { Rol selectedRol = context.Roles.Find(1); User u = new User(); u.Email = user.Email; u.Password = user.Password; u.Username = user.Username; u.Email = user.Email; u.Rol = selectedRol; u.IsActive = true; context.Users.Add(u); context.SaveChanges(); } return(View(user)); }
public void Initialize(SATContext context, IEncryptor encryptor) { if (!context.Users.Any()) { context.Users.Add( new User() { Username = "******", Password = encryptor.encrypt("123"), Email = "*****@*****.**", Rol = new Rol() { RolId = RolId.SOPORTE_SISTEMAS, RolName = "Soporte de sistemas" }, IsActive = true }); } if (!context.Provinces.Any()) { Province managua = new Province() { ProvinceName = "Managua" }; Province nuevaSegovia = new Province() { ProvinceName = "NuevaSegovia" }; Province esteli = new Province() { ProvinceName = "Esteli" }; Province matagalpa = new Province() { ProvinceName = "Matagalpa" }; Province leon = new Province() { ProvinceName = "Leon" }; Municipality tipitapa = new Municipality() { MunicipalityName = "Tipitapa" }; Municipality managuaCabecera = new Municipality() { MunicipalityName = "Managua" }; List <Municipality> municipalities = new List <Municipality>() { tipitapa, managuaCabecera }; managua.Municipalities = municipalities; Municipality ocotal = new Municipality() { MunicipalityName = "Ocotal" }; Municipality jalapa = new Municipality() { MunicipalityName = "Jalapa" }; nuevaSegovia.Municipalities = new List <Municipality>() { ocotal, jalapa }; Municipality cabeceraEsteli = new Municipality() { MunicipalityName = "Esteli" }; Municipality condega = new Municipality() { MunicipalityName = "Condega" }; esteli.Municipalities = new List <Municipality>() { cabeceraEsteli, condega }; Municipality leonCabecera = new Municipality() { MunicipalityName = "Leon" }; Municipality larreynaga = new Municipality() { MunicipalityName = "Larreynaga" }; leon.Municipalities = new List <Municipality>() { leonCabecera, larreynaga }; Branch asososca = new Branch() { BranchName = "Asososca", Municipality = managuaCabecera }; Branch altamira = new Branch() { BranchName = "Altamira", Municipality = managuaCabecera }; Branch sucursalOcotal = new Branch() { BranchName = "Ocotal", Municipality = ocotal }; Branch sucursalEsteli = new Branch() { BranchName = "Esteli", Municipality = cabeceraEsteli }; Branch sucursalLeon = new Branch() { BranchName = "Leon", Municipality = leonCabecera }; context.Provinces.Add(managua); context.Provinces.Add(nuevaSegovia); context.Provinces.Add(esteli); context.Provinces.Add(matagalpa); context.Provinces.Add(leon); context.Branches.Add(asososca); context.Branches.Add(altamira); context.Branches.Add(sucursalOcotal); context.Branches.Add(sucursalEsteli); context.Branches.Add(sucursalLeon); } if (!context.Source.Any()) { context.Source.Add(new Source() { SourceName = "(AV) AquaVisum", TaskType = TaskType.AsistenciaTecnica, IsActive = true }); context.Source.Add(new Source() { SourceName = "(SCI) Sistema de Inventario", TaskType = TaskType.AsistenciaTecnica, IsActive = true }); } context.SaveChanges(); }