public IHttpActionResult Post([FromBody] ContractDetail contract) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } People person = _context.Person.FirstOrDefault(x => x.Id == contract.PeopleId); if (person == null) { person = _context.Person.FirstOrDefault(x => x.CUNI == contract.CUNI); } if (person == null) { return(NotFound()); } bool valid = true; string errorMessage = ""; if (contract.EndDate < contract.StartDate) { valid = false; errorMessage += "La fecha fin no puede ser menor a la fecha inicio"; } if (_context.Dependencies.FirstOrDefault(x => x.Id == contract.DependencyId) == null) { valid = false; errorMessage += "La Dependencia no es valida"; } if (_context.Position.FirstOrDefault(x => x.Id == contract.PositionsId) == null) { valid = false; errorMessage += "El Cargo no es valido"; } if (_context.TableOfTableses.FirstOrDefault(x => x.Type == "VINCULACION" && x.Id == contract.Linkage) == null) { valid = false; errorMessage += "Esta vinculación no es valida"; } if (_context.TableOfTableses.FirstOrDefault(x => x.Type == "DEDICACION" && x.Value == contract.Dedication) == null) { valid = false; errorMessage += "Esta dedicación no es valida"; } if (valid) { contract.PeopleId = person.Id; contract.CUNI = person.CUNI; contract.BranchesId = _context.Dependencies.FirstOrDefault(x => x.Id == contract.DependencyId).BranchesId; contract.Id = ContractDetail.GetNextId(_context); contract.PositionDescription = contract.PositionDescription != null?contract.PositionDescription.ToUpper() : null; contract.Active = true; _context.ContractDetails.Add(contract); _context.SaveChanges(); var user = auth.getUser(Request); // create user in SAP B1.AddOrUpdatePerson(user.Id, person); return(Created(new Uri(Request.RequestUri + "/" + contract.Id), contract)); } return(BadRequest(errorMessage)); }
public IHttpActionResult saveLastAltaExcel(int id) { var tempAlta = _context.TempAltas.Where(x => x.BranchesId == id && x.State == "UPLOADED"); ValidateAuth auth = new ValidateAuth(); CustomUser user = auth.getUser(Request); if (tempAlta.Count() < 0) { return(NotFound()); } foreach (var alta in tempAlta) { var person = new People(); var depId = _context.Dependencies.FirstOrDefault(x => x.Cod == alta.Dependencia).Id; person = _context.Person.FirstOrDefault(x => x.CUNI == alta.CUNI); var exist = _context.ContractDetails.Where ( x => x.CUNI == alta.CUNI && x.PeopleId == person.Id && x.DependencyId == depId && x.Dedication == "TH" && x.Linkage == 3 && x.PositionsId == 26 && x.StartDate == alta.StartDate && x.EndDate == alta.EndDate ).ToList().Any(); if (!exist) { var contract = new ContractDetail(); contract.Id = ContractDetail.GetNextId(_context); contract.DependencyId = depId; contract.CUNI = person.CUNI; contract.PeopleId = person.Id; contract.BranchesId = alta.BranchesId; contract.Dedication = "TH"; contract.Linkage = 3; contract.PositionDescription = "Docente Tiempo Horario"; contract.PositionsId = 26; contract.StartDate = alta.StartDate; contract.EndDate = alta.EndDate; contract.Active = true; _context.ContractDetails.Add(contract); alta.State = "INBANKH"; } else { alta.State = "DUPLICATE"; } } _context.SaveChanges(); tempAlta = _context.TempAltas.Where(x => x.BranchesId == id && x.State == "INBANKH"); foreach (var alta in tempAlta) { var person = new People(); person = _context.Person.FirstOrDefault(x => x.CUNI == alta.CUNI); var res = B1.AddOrUpdatePerson(user.Id, person, "DOCENTE T.H."); if (!res.Contains("ERROR")) { alta.State = "INSAP"; } else { alta.State = "ERRORINSAP"; } } _context.SaveChanges(); return(Ok(tempAlta)); }