public IHttpActionResult addalltoSAP()
        {
            var           date   = new DateTime(2017, 1, 1);
            List <People> person = _context.ContractDetails.Include(x => x.People).Include(x => x.Positions).
                                   Where(y => (y.EndDate > date || y.EndDate == null) && y.DependencyId == 189
                                         ).Select(x => x.People).Distinct().ToList();

            //string query = "SELECT p.* FROM ADMNALRRHH.\"People\" p\r\ninner join ucatolica.ocrd bp\r\non concat(\'R\', p.cuni) = bp.\"CardCode\"";
            //List<People> person = _context.Database.SqlQuery<People>(query).ToList();

            //person = person.Where(x => x.CUNI == "RFA940908").ToList();
            B1Connection b1  = B1Connection.Instance();
            var          usr = auth.getUser(Request);
            int          i   = 0;

            foreach (var p in person)
            {
                i++;
                var X = b1.AddOrUpdatePerson(usr.Id, p);
                if (X.Contains("ERROR"))
                {
                    X = "";
                }
            }

            return(Ok());
        }
        public IHttpActionResult addalltoSAPNow()
        {
            //actualiza a todas las personas de la vida para mostrar sus puestos, si no tienen la descripción en SAP
            var posSubject = _context.Database.SqlQuery <PositionSubjectViewModel>("select lc.\"PeopleId\" as \"People_Id\",p.\"NameAbr\" as \"NameAbr\" " +
                                                                                   "from " + ConfigurationManager.AppSettings["B1CompanyDB"] + ".\"OHEM\" o " +
                                                                                   "inner join " + CustomSchema.Schema + ".\"LASTCONTRACTS\" lc " +
                                                                                   "on o.\"ExtEmpNo\"=lc.cuni " +
                                                                                   "inner join " + CustomSchema.Schema + ".\"Position\" p " +
                                                                                   "on p.\"Id\"=lc.\"PositionsId\" " +
                                                                                   "where o.\"jobTitle\" is null ;").ToList();
            var usr = auth.getUser(Request);

            foreach (var p in posSubject)
            {
                var thisPerson = _context.Person.FirstOrDefault(x => x.Id == p.People_Id);
                var result     = B1.AddOrUpdatePerson(usr.Id, thisPerson, p.NameAbr);
                p.Result = result;
            }

            return(Ok(posSubject));
        }
Beispiel #3
0
        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));
        }