Esempio n. 1
0
        public async Task <IActionResult> PutObjectSetParcel([FromRoute] int id, [FromBody] ObjectSetParcel objectSetParcel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != objectSetParcel.Id)
            {
                return(BadRequest());
            }

            _context.Entry(objectSetParcel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ObjectSetParcelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> ToExcel([FromBody] Excel excel)
        {
            IEnumerable <ObjectSetParcel> parcels    = _context.ObjectSetParcel;
            IEnumerable <ObjectSet>       objects    = _context.ObjectSet;
            List <ObjectSetParcel>        parcelsRes = new List <ObjectSetParcel>();
            ObjectSetParcel prcl = new ObjectSetParcel();
            ObjectSet       obj  = new ObjectSet();

            for (int i = 0; i < excel.Ids.Count(); i++)
            {
                prcl = parcels.FirstOrDefault(u => u.Id == excel.Ids[i]);

                obj = objects.FirstOrDefault(u => u.Id == prcl.Id);
                obj.ObjectSetParcel = null;
                prcl.IdNavigation   = obj;

                parcelsRes.Add(prcl);
            }

            var fileDownloadName = "Участки.xlsx";

            using (var package = createExcelPackage(parcelsRes))
            {
                package.SaveAs(new FileInfo(Path.Combine(@"C:\Users\user\Downloads", fileDownloadName)));
            }
            return(Ok());
        }
Esempio n. 3
0
        public async Task <IActionResult> PostObjectSetParcel([FromBody] ObjectSetParcel objectSetParcel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ObjectSetParcel.Add(objectSetParcel);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ObjectSetParcelExists(objectSetParcel.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetObjectSetParcel", new { id = objectSetParcel.Id }, objectSetParcel));
        }
        private string parecelToString(ObjectSetParcel parcel)
        {
            string res = "";

            res = "Площадь: " + parcel.Area + ", Тип использования: " + parcel.UsageType;

            return(res);
        }
Esempio n. 5
0
        public IEnumerable <ObjectSetParcel> GetObjectSetParcel()
        {
            IEnumerable <ObjectSetParcel> parcels = _context.ObjectSetParcel;
            IEnumerable <ObjectSet>       objects = _context.ObjectSet;
            ObjectSetParcel prc = new ObjectSetParcel();
            ObjectSet       obj = new ObjectSet();

            for (int i = 0; i < parcels.Count(); i++)
            {
                obj = objects.FirstOrDefault(u => u.Id == parcels.ElementAt(i).Id);
                obj.ObjectSetParcel = null;
                parcels.ElementAt(i).IdNavigation = obj;
            }

            return(parcels);
        }
        public async Task <IActionResult> GetSalary([FromRoute] int month)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <SalaryClass>              salResult      = new List <SalaryClass>();
            IEnumerable <ContractSet>       contracts      = _context.ContractSet;
            IEnumerable <AppraiserContract> contrAppraiser = _context.AppraiserContract;
            IEnumerable <UserSetAppraiser>  appraisers     = _context.UserSetAppraiser;
            IEnumerable <UserSet>           users          = _context.UserSet;
            IEnumerable <SalarySettingsSet> settings       = _context.SalarySettingsSet;
            IEnumerable <ObjectSetFlat>     flats          = _context.ObjectSetFlat;
            IEnumerable <ObjectSetCar>      cars           = _context.ObjectSetCar;
            IEnumerable <ObjectSetParcel>   parcels        = _context.ObjectSetParcel;
            SalaryClass       sal    = new SalaryClass();
            ContractSet       cntr   = new ContractSet();
            AppraiserContract conApp = new AppraiserContract();
            UserSetAppraiser  appr   = new UserSetAppraiser();
            UserSet           usr    = new UserSet();
            ObjectSetFlat     flt    = new ObjectSetFlat();
            ObjectSetCar      car    = new ObjectSetCar();
            ObjectSetParcel   prc    = new ObjectSetParcel();

            DateTime currDate    = new DateTime();
            DateTime monthStart  = new DateTime();
            DateTime monthFinish = new DateTime();

            currDate = DateTime.Now;

            if (month != 0)
            {
                month       = month * (-1);
                currDate    = currDate.AddMonths(month);
                monthFinish = getLastDay(currDate);
            }
            else
            {
                monthFinish = currDate;
            }

            monthStart = new DateTime(currDate.Year, currDate.Month, 1);

            contracts = contracts.Where(cn => DateTime.Compare(cn.FinishDate, monthStart) >= 0 && DateTime.Compare(cn.FinishDate, monthFinish) <= 0);

            for (int i = 0; i < contracts.Count(); i++)
            {
                sal    = null;
                conApp = null;
                appr   = null;
                usr    = null;

                conApp = contrAppraiser.FirstOrDefault(c => c.ContractId == contracts.ElementAt(i).Id);
                appr   = appraisers.FirstOrDefault(a => a.Id == conApp.AppraiserId);
                usr    = users.FirstOrDefault(u => u.Id == appr.Id);

                flt = flats.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ObjectId);
                car = cars.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ObjectId);
                prc = parcels.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ObjectId);

                sal = salResult.FirstOrDefault(s => s.Surname == usr.Surname);

                if (sal == null)
                {
                    sal = new SalaryClass();
                    if (flt != null)
                    {
                        sal.ContractsFlat.Add(contracts.ElementAt(i));
                    }
                    else
                    {
                        if (prc != null)
                        {
                            sal.ContractsParcel.Add(contracts.ElementAt(i));
                        }
                        else
                        {
                            sal.ContractsCar.Add(contracts.ElementAt(i));
                        }
                    }
                    sal.Surname    = usr.Surname;
                    sal.Name       = usr.Name;
                    sal.Patronymic = usr.Patronymic;
                    sal.Month      = month;

                    contracts.ElementAt(i).Client            = null;
                    contracts.ElementAt(i).AppraiserContract = null;
                    contracts.ElementAt(i).Object            = null;

                    salResult.Add(sal);
                }
                else
                {
                    salResult.Remove(sal);
                    if (flt != null)
                    {
                        contracts.ElementAt(i).Client            = null;
                        contracts.ElementAt(i).AppraiserContract = null;
                        contracts.ElementAt(i).Object            = null;
                        sal.ContractsFlat.Add(contracts.ElementAt(i));
                    }
                    else
                    {
                        if (prc != null)
                        {
                            contracts.ElementAt(i).Client            = null;
                            contracts.ElementAt(i).AppraiserContract = null;
                            contracts.ElementAt(i).Object            = null;
                            sal.ContractsParcel.Add(contracts.ElementAt(i));
                        }
                        else
                        {
                            contracts.ElementAt(i).Client            = null;
                            contracts.ElementAt(i).AppraiserContract = null;
                            contracts.ElementAt(i).Object            = null;
                            sal.ContractsCar.Add(contracts.ElementAt(i));
                        }
                    }
                    salResult.Add(sal);
                }
            }

            for (int i = 0; i < salResult.Count(); i++)
            {
                salResult.ElementAt(i).ContractsCount = salResult.ElementAt(i).ContractsCar.Count + salResult.ElementAt(i).ContractsFlat.Count + salResult.ElementAt(i).ContractsParcel.Count;

                foreach (ContractSet contr in salResult.ElementAt(i).ContractsFlat)
                {
                    salResult.ElementAt(i).Salary += contr.ContractSumm / 100 * settings.First().FlatPercent;
                }

                foreach (ContractSet contr in salResult.ElementAt(i).ContractsCar)
                {
                    salResult.ElementAt(i).Salary += contr.ContractSumm / 100 * settings.First().CarPercent;
                }

                foreach (ContractSet contr in salResult.ElementAt(i).ContractsParcel)
                {
                    salResult.ElementAt(i).Salary += contr.ContractSumm / 100 * settings.First().ParcelPercent;
                }

                salResult.ElementAt(i).Salary = Math.Round(salResult.ElementAt(i).Salary, MidpointRounding.ToEven);
            }

            if (salResult == null)
            {
                return(NotFound());
            }

            return(Ok(salResult));
        }
        public async Task <IActionResult> ToExcel([FromRoute] int month)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <SalaryClass>              salResult      = new List <SalaryClass>();
            IEnumerable <ContractSet>       contracts      = _context.ContractSet;
            IEnumerable <AppraiserContract> contrAppraiser = _context.AppraiserContract;
            IEnumerable <UserSetAppraiser>  appraisers     = _context.UserSetAppraiser;
            IEnumerable <UserSet>           users          = _context.UserSet;
            IEnumerable <SalarySettingsSet> settings       = _context.SalarySettingsSet;
            IEnumerable <ObjectSetFlat>     flats          = _context.ObjectSetFlat;
            IEnumerable <ObjectSetCar>      cars           = _context.ObjectSetCar;
            IEnumerable <ObjectSetParcel>   parcels        = _context.ObjectSetParcel;
            SalaryClass       sal    = new SalaryClass();
            ContractSet       cntr   = new ContractSet();
            AppraiserContract conApp = new AppraiserContract();
            UserSetAppraiser  appr   = new UserSetAppraiser();
            UserSet           usr    = new UserSet();
            ObjectSetFlat     flt    = new ObjectSetFlat();
            ObjectSetCar      car    = new ObjectSetCar();
            ObjectSetParcel   prc    = new ObjectSetParcel();

            DateTime currDate    = new DateTime();
            DateTime monthStart  = new DateTime();
            DateTime monthFinish = new DateTime();

            currDate = DateTime.Now;

            if (month != 0)
            {
                month       = month * (-1);
                currDate    = currDate.AddMonths(month);
                monthFinish = getLastDay(currDate);
            }
            else
            {
                monthFinish = currDate;
            }

            monthStart = new DateTime(currDate.Year, currDate.Month, 1);

            contracts = contracts.Where(cn => DateTime.Compare(cn.FinishDate, monthStart) >= 0 && DateTime.Compare(cn.FinishDate, monthFinish) <= 0);

            for (int i = 0; i < contracts.Count(); i++)
            {
                sal    = null;
                conApp = null;
                appr   = null;
                usr    = null;

                conApp = contrAppraiser.FirstOrDefault(c => c.ContractId == contracts.ElementAt(i).Id);
                appr   = appraisers.FirstOrDefault(a => a.Id == conApp.AppraiserId);
                usr    = users.FirstOrDefault(u => u.Id == appr.Id);

                flt = flats.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ObjectId);
                car = cars.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ObjectId);
                prc = parcels.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ObjectId);

                sal = salResult.FirstOrDefault(s => s.Surname == usr.Surname);

                if (sal == null)
                {
                    sal = new SalaryClass();
                    if (flt != null)
                    {
                        sal.ContractsFlat.Add(contracts.ElementAt(i));
                    }
                    else
                    {
                        if (prc != null)
                        {
                            sal.ContractsParcel.Add(contracts.ElementAt(i));
                        }
                        else
                        {
                            sal.ContractsCar.Add(contracts.ElementAt(i));
                        }
                    }
                    sal.Surname    = usr.Surname;
                    sal.Name       = usr.Name;
                    sal.Patronymic = usr.Patronymic;
                    sal.Month      = month;

                    contracts.ElementAt(i).Client            = null;
                    contracts.ElementAt(i).AppraiserContract = null;
                    contracts.ElementAt(i).Object            = null;

                    salResult.Add(sal);
                }
                else
                {
                    salResult.Remove(sal);
                    if (flt != null)
                    {
                        contracts.ElementAt(i).Client            = null;
                        contracts.ElementAt(i).AppraiserContract = null;
                        contracts.ElementAt(i).Object            = null;
                        sal.ContractsFlat.Add(contracts.ElementAt(i));
                    }
                    else
                    {
                        if (prc != null)
                        {
                            contracts.ElementAt(i).Client            = null;
                            contracts.ElementAt(i).AppraiserContract = null;
                            contracts.ElementAt(i).Object            = null;
                            sal.ContractsParcel.Add(contracts.ElementAt(i));
                        }
                        else
                        {
                            contracts.ElementAt(i).Client            = null;
                            contracts.ElementAt(i).AppraiserContract = null;
                            contracts.ElementAt(i).Object            = null;
                            sal.ContractsCar.Add(contracts.ElementAt(i));
                        }
                    }
                    salResult.Add(sal);
                }
            }

            for (int i = 0; i < salResult.Count(); i++)
            {
                salResult.ElementAt(i).ContractsCount = salResult.ElementAt(i).ContractsCar.Count + salResult.ElementAt(i).ContractsFlat.Count + salResult.ElementAt(i).ContractsParcel.Count;

                foreach (ContractSet contr in salResult.ElementAt(i).ContractsFlat)
                {
                    salResult.ElementAt(i).Salary += contr.ContractSumm / 100 * settings.First().FlatPercent;
                }

                foreach (ContractSet contr in salResult.ElementAt(i).ContractsCar)
                {
                    salResult.ElementAt(i).Salary += contr.ContractSumm / 100 * settings.First().CarPercent;
                }

                foreach (ContractSet contr in salResult.ElementAt(i).ContractsParcel)
                {
                    salResult.ElementAt(i).Salary += contr.ContractSumm / 100 * settings.First().ParcelPercent;
                }
            }

            string[] monthArr = new string[] { "Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь" };

            var fileDownloadName = "Зарплата - " + monthArr[monthStart.Month - 1] + ".xlsx";

            using (var package = createExcelPackage(salResult))
            {
                package.SaveAs(new FileInfo(Path.Combine(@"C:\Users\user\Downloads", fileDownloadName)));
            }
            return(Ok());
        }
        public IEnumerable <ContractSet> GetContractSet()
        {
            IEnumerable <ContractSet>         contracts         = _context.ContractSet;
            IEnumerable <ObjectSet>           objects           = _context.ObjectSet;
            IEnumerable <ObjectSetFlat>       flats             = _context.ObjectSetFlat;
            IEnumerable <ObjectSetCar>        cars              = _context.ObjectSetCar;
            IEnumerable <ObjectSetParcel>     parcels           = _context.ObjectSetParcel;
            IEnumerable <ClientSet>           clients           = _context.ClientSet;
            IEnumerable <ClientSetIndividual> clientsIndiv      = _context.ClientSetIndividual;
            IEnumerable <ClientSetEntity>     clientsEnt        = _context.ClientSetEntity;
            IEnumerable <UserSetAppraiser>    apraisers         = _context.UserSetAppraiser;
            IEnumerable <AppraiserContract>   apraisersContract = _context.AppraiserContract;
            IEnumerable <UserSet>             users             = _context.UserSet;
            IEnumerable <AddressSet>          addresses         = _context.AddressSet;
            ContractSet         cntr    = new ContractSet();
            ClientSet           clnt    = new ClientSet();
            ClientSetIndividual indv    = new ClientSetIndividual();
            ClientSetEntity     ent     = new ClientSetEntity();
            ObjectSet           obj     = new ObjectSet();
            ObjectSetFlat       flt     = new ObjectSetFlat();
            ObjectSetCar        cr      = new ObjectSetCar();
            ObjectSetParcel     prcl    = new ObjectSetParcel();
            UserSetAppraiser    apr     = new UserSetAppraiser();
            AppraiserContract   aprCntr = new AppraiserContract();
            UserSet             usr     = new UserSet();
            AddressSet          adr     = new AddressSet();

            for (int i = 0; i < contracts.Count(); i++)
            {
                clnt             = clients.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ClientId);
                clnt.ContractSet = null;
                indv             = clientsIndiv.FirstOrDefault(u => u.Id == clnt.Id);
                ent = clientsEnt.FirstOrDefault(u => u.Id == clnt.Id);
                if (indv != null)
                {
                    indv.IdNavigation = null;
                    adr = addresses.FirstOrDefault(u => u.Id == indv.AddressOfResidenceId);
                    adr.ClientSetIndividual  = null;
                    indv.AddressOfResidence  = adr;
                    clnt.ClientSetIndividual = indv;
                }
                else
                {
                    ent.IdNavigation = null;
                    adr = addresses.FirstOrDefault(u => u.Id == ent.LegalAddressId);
                    adr.ClientSetEntity  = null;
                    ent.LegalAddress     = adr;
                    clnt.ClientSetEntity = ent;
                }
                contracts.ElementAt(i).Client = clnt;

                obj             = objects.FirstOrDefault(u => u.Id == contracts.ElementAt(i).ObjectId);
                obj.ContractSet = null;
                flt             = flats.FirstOrDefault(u => u.Id == obj.Id);
                cr   = cars.FirstOrDefault(u => u.Id == obj.Id);
                prcl = parcels.FirstOrDefault(u => u.Id == obj.Id);
                if (flt != null)
                {
                    flt.IdNavigation = null;
                    adr = addresses.FirstOrDefault(u => u.Id == flt.AddressId);
                    adr.ObjectSetFlat = null;
                    flt.Address       = adr;
                    obj.ObjectSetFlat = flt;
                }
                else
                {
                    if (prcl != null)
                    {
                        prcl.IdNavigation   = null;
                        obj.ObjectSetParcel = prcl;
                    }
                    else
                    {
                        cr.IdNavigation  = null;
                        obj.ObjectSetCar = cr;
                    }
                }
                contracts.ElementAt(i).Object = obj;

                aprCntr = apraisersContract.FirstOrDefault(u => u.ContractId == contracts.ElementAt(i).Id);
                apr     = apraisers.FirstOrDefault(u => u.Id == aprCntr.AppraiserId);
                apr.AppraiserContract = null;
                usr = users.FirstOrDefault(u => u.Id == apr.Id);
                usr.UserSetAppraiser = null;
                apr.IdNavigation     = usr;
                aprCntr.Appraiser    = apr;
                aprCntr.Contract     = null;

                AppraiserContract[] arr = new AppraiserContract[1];
                arr[0] = aprCntr;
                contracts.ElementAt(i).AppraiserContract = arr;
            }

            return(contracts);
        }
        public async Task <IActionResult> ToExcel([FromBody] Excel excel)
        {
            List <ContractSet>                contractsRes      = new List <ContractSet>();
            IEnumerable <ContractSet>         contracts         = _context.ContractSet;
            IEnumerable <ObjectSet>           objects           = _context.ObjectSet;
            IEnumerable <ObjectSetFlat>       flats             = _context.ObjectSetFlat;
            IEnumerable <ObjectSetCar>        cars              = _context.ObjectSetCar;
            IEnumerable <ObjectSetParcel>     parcels           = _context.ObjectSetParcel;
            IEnumerable <ClientSet>           clients           = _context.ClientSet;
            IEnumerable <ClientSetIndividual> clientsIndiv      = _context.ClientSetIndividual;
            IEnumerable <ClientSetEntity>     clientsEnt        = _context.ClientSetEntity;
            IEnumerable <UserSetAppraiser>    apraisers         = _context.UserSetAppraiser;
            IEnumerable <AppraiserContract>   apraisersContract = _context.AppraiserContract;
            IEnumerable <UserSet>             users             = _context.UserSet;
            IEnumerable <AddressSet>          addresses         = _context.AddressSet;
            ContractSet         cntr    = new ContractSet();
            ClientSet           clnt    = new ClientSet();
            ClientSetIndividual indv    = new ClientSetIndividual();
            ClientSetEntity     ent     = new ClientSetEntity();
            ObjectSet           obj     = new ObjectSet();
            ObjectSetFlat       flt     = new ObjectSetFlat();
            ObjectSetCar        cr      = new ObjectSetCar();
            ObjectSetParcel     prcl    = new ObjectSetParcel();
            UserSetAppraiser    apr     = new UserSetAppraiser();
            AppraiserContract   aprCntr = new AppraiserContract();
            UserSet             usr     = new UserSet();
            AddressSet          adr     = new AddressSet();

            for (int i = 0; i < excel.Ids.Count(); i++)
            {
                cntr = contracts.FirstOrDefault(u => u.Id == excel.Ids[i]);

                clnt             = clients.FirstOrDefault(u => u.Id == cntr.ClientId);
                clnt.ContractSet = null;
                indv             = clientsIndiv.FirstOrDefault(u => u.Id == clnt.Id);
                ent = clientsEnt.FirstOrDefault(u => u.Id == clnt.Id);
                if (indv != null)
                {
                    indv.IdNavigation = null;
                    adr = addresses.FirstOrDefault(u => u.Id == indv.AddressOfResidenceId);
                    adr.ClientSetIndividual  = null;
                    indv.AddressOfResidence  = adr;
                    clnt.ClientSetIndividual = indv;
                }
                else
                {
                    ent.IdNavigation = null;
                    adr = addresses.FirstOrDefault(u => u.Id == ent.LegalAddressId);
                    adr.ClientSetEntity  = null;
                    ent.LegalAddress     = adr;
                    clnt.ClientSetEntity = ent;
                }
                cntr.Client = clnt;

                obj             = objects.FirstOrDefault(u => u.Id == cntr.ObjectId);
                obj.ContractSet = null;
                flt             = flats.FirstOrDefault(u => u.Id == obj.Id);
                cr   = cars.FirstOrDefault(u => u.Id == obj.Id);
                prcl = parcels.FirstOrDefault(u => u.Id == obj.Id);
                if (flt != null)
                {
                    flt.IdNavigation = null;
                    adr = addresses.FirstOrDefault(u => u.Id == flt.AddressId);
                    adr.ObjectSetFlat = null;
                    flt.Address       = adr;
                    obj.ObjectSetFlat = flt;
                }
                else
                {
                    if (prcl != null)
                    {
                        prcl.IdNavigation   = null;
                        obj.ObjectSetParcel = prcl;
                    }
                    else
                    {
                        cr.IdNavigation  = null;
                        obj.ObjectSetCar = cr;
                    }
                }
                cntr.Object = obj;

                aprCntr = apraisersContract.FirstOrDefault(u => u.ContractId == cntr.Id);
                apr     = apraisers.FirstOrDefault(u => u.Id == aprCntr.AppraiserId);
                apr.AppraiserContract = null;
                usr = users.FirstOrDefault(u => u.Id == apr.Id);
                usr.UserSetAppraiser = null;
                apr.IdNavigation     = usr;
                aprCntr.Appraiser    = apr;
                aprCntr.Contract     = null;

                AppraiserContract[] arr = new AppraiserContract[1];
                arr[0] = aprCntr;
                cntr.AppraiserContract = arr;

                contractsRes.Add(cntr);
            }

            var fileDownloadName = "Договоры.xlsx";

            using (var package = createExcelPackage(contractsRes))
            {
                package.SaveAs(new FileInfo(Path.Combine(@"C:\Users\user\Downloads", fileDownloadName)));
            }
            return(Ok());
        }