Ejemplo n.º 1
0
        public IActionResult ReportGet(string id)
        {
            ESSInfo         info   = _context.ESSInfos.FirstOrDefault(x => x.ESSCode == id);
            ReportViewModel report = new ReportViewModel
            {
                ESSInfo        = info,
                Employee       = _context.Employees.FirstOrDefault(x => x.Id == info.EmployeeId),
                EmpProductMap  = _context.EmpProductMaps.Where(x => x.ESSInfoId == info.Id).Include(x => x.Product).ToList(),
                EmpDivisionMap = _context.EmpDivisionMaps.Where(x => x.ESSInfoId == info.Id).Include(x => x.Division).ToList(),
                EmpDistrictMap = _context.EmpDistrictMaps.Where(x => x.ESSInfoId == info.Id).Include(x => x.District).ToList(),
                EmpUpazilaMap  = _context.EmpUpazilaMaps.Where(x => x.ESSInfoId == info.Id).Include(x => x.Upazila).ToList()
            };

            return(View(report));
        }
Ejemplo n.º 2
0
        public string GenerateESSCode()
        {
            string  month       = DateTime.UtcNow.ToString("MM");
            string  year        = DateTime.UtcNow.Year.ToString();
            ESSInfo lastEssInfo = _context.ESSInfos.LastOrDefault();
            int     essNumber   = 1;

            if (lastEssInfo != null)
            {
                essNumber = int.Parse(lastEssInfo.ESSCode.Substring(6));
            }

            string essCode = month + year + ++essNumber;

            return(essCode);
        }
Ejemplo n.º 3
0
        public IActionResult Create(ESSEntryModel model)
        {
            if (model.ESSCode == null && model.EmployeeId == 0)
            {
                Employee employee = new Employee
                {
                    Name        = model.EmployeeName,
                    Designation = model.Designation,
                    Phone       = model.EmployeePhone
                };
                _context.Employees.Add(employee);

                string essCode = _ess.GenerateESSCode();

                ESSInfo info = new ESSInfo
                {
                    EmployeeId  = employee.Id,
                    EntryTime   = DateTime.UtcNow.Date,
                    WorkingArea = model.WorkingArea,
                    ESSCode     = essCode
                };
                _context.ESSInfos.Add(info);

                _context.SaveChanges();

                return(Json(new { essCode, employeeId = employee.Id }));
            }
            else
            {
                Employee employee = new Employee
                {
                    Id          = model.EmployeeId,
                    Name        = model.EmployeeName,
                    Designation = model.Designation,
                    Phone       = model.EmployeePhone
                };
                _context.Employees.Update(employee);

                ESSInfo info = _context.ESSInfos.Where(x => x.ESSCode == model.ESSCode).FirstOrDefault();

                info.WorkingArea = model.WorkingArea;

                _context.ESSInfos.Update(info);

                if (model.Divisions.Count() > 0)
                {
                    List <EmpDivisionMap> empDivisionMap = _context.EmpDivisionMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpDivisionMaps.RemoveRange(empDivisionMap);

                    foreach (var item in model.Divisions)
                    {
                        Division       division    = _context.Divisions.Where(x => x.Name == item).FirstOrDefault();
                        EmpDivisionMap empDivision = new EmpDivisionMap
                        {
                            EmployeeId = model.EmployeeId,
                            DivisionId = division.Id,
                            ESSInfoId  = info.Id
                        };
                        _context.EmpDivisionMaps.Add(empDivision);
                    }
                }
                else
                {
                    List <EmpDivisionMap> empDivisionMap = _context.EmpDivisionMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpDivisionMaps.RemoveRange(empDivisionMap);
                }

                if (model.Districts.Count() > 0)
                {
                    List <EmpDistrictMap> empDistrictMaps = _context.EmpDistrictMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpDistrictMaps.RemoveRange(empDistrictMaps);

                    foreach (var item in model.Districts)
                    {
                        District       district    = _context.Districts.Where(x => x.Name == item).FirstOrDefault();
                        EmpDistrictMap empDistrict = new EmpDistrictMap
                        {
                            EmployeeId = model.EmployeeId,
                            DistrictId = district.Id,
                            ESSInfoId  = info.Id
                        };
                        _context.EmpDistrictMaps.Add(empDistrict);
                    }
                }
                else
                {
                    List <EmpDistrictMap> empDistrictMaps = _context.EmpDistrictMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpDistrictMaps.RemoveRange(empDistrictMaps);
                }

                if (model.Upazilas.Count() > 0)
                {
                    List <EmpUpazilaMap> empUpazilaMaps = _context.EmpUpazilaMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpUpazilaMaps.RemoveRange(empUpazilaMaps);

                    foreach (var item in model.Upazilas)
                    {
                        Upazila       upazila    = _context.Upazilas.Where(x => x.Name == item).FirstOrDefault();
                        EmpUpazilaMap empUpazila = new EmpUpazilaMap
                        {
                            EmployeeId = model.EmployeeId,
                            UpazilaId  = upazila.Id,
                            ESSInfoId  = info.Id
                        };
                        _context.EmpUpazilaMaps.Add(empUpazila);
                    }
                }
                else
                {
                    List <EmpDistrictMap> empDistrictMaps = _context.EmpDistrictMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpDistrictMaps.RemoveRange(empDistrictMaps);
                }

                if (model.Products.Count() > 0)
                {
                    List <EmpProductMap> empProductMaps = _context.EmpProductMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpProductMaps.RemoveRange(empProductMaps);

                    foreach (var item in model.Products)
                    {
                        EmpProductMap empProduct = new EmpProductMap
                        {
                            EmployeeId = model.EmployeeId,
                            ESSInfoId  = info.Id,
                            Price      = item.Price,
                            Quantity   = item.Quantity,
                            ProductId  = item.Id
                        };
                        _context.EmpProductMaps.Add(empProduct);
                    }
                }
                else
                {
                    List <EmpProductMap> empProductMaps = _context.EmpProductMaps.Where(x => x.ESSInfoId == info.Id).ToList();
                    _context.EmpProductMaps.RemoveRange(empProductMaps);
                }

                _context.SaveChanges();
            }

            return(View());
        }