public ActionResult CreateUpdateLoanReturn(ReturnLoanModel returnLoanModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var returnLoan = new ReturnLoan();

            if (returnLoanModel.Id > 0)
            {
                returnLoan = FarmManagementEntities.ReturnLoans.Single(x => x.Id == returnLoanModel.Id);
            }

            returnLoan.LoanId            = returnLoanModel.LoanId;
            returnLoan.InstallmentAmount = returnLoanModel.InstallmentAmount;
            returnLoan.AccountId         = returnLoanModel.AccountId;
            returnLoan.UserId            = returnLoanModel.UserId;
            returnLoan.PaidDate          = returnLoanModel.PaidDate;

            if (returnLoanModel.Id == 0)
            {
                returnLoan.InsertDate = DateTime.Now;
                FarmManagementEntities.ReturnLoans.Add(returnLoan);
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, returnLoanModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Пример #2
0
        public ActionResult CreateUpdateTemporaryEmployeeSalary(TemporaryEmployeeSalaryModel tempEmpModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var tempEmpSalary = new TemporaryEmployeeSalary();

            if (tempEmpModel.Id > 0)
            {
                tempEmpSalary = FarmManagementEntities.TemporaryEmployeeSalaries.Single(x => x.Id == tempEmpModel.Id);
            }

            tempEmpSalary.Year         = tempEmpModel.Year;
            tempEmpSalary.Month        = tempEmpModel.Month;
            tempEmpSalary.MorningWages = tempEmpModel.MorningWages;
            tempEmpSalary.NightWages   = tempEmpModel.NightWages;

            if (tempEmpModel.Id == 0)
            {
                tempEmpSalary.InsertDate = DateTime.Now;
                FarmManagementEntities.TemporaryEmployeeSalaries.Add(tempEmpSalary);
            }
            else
            {
                tempEmpSalary.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, tempEmpModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
        public ActionResult CreateUpdatePaidLoan(PaidLoanModel paidLoanModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var paidLoan = new PaidLoan();

            if (paidLoanModel.Id > 0)
            {
                paidLoan = FarmManagementEntities.PaidLoans.Single(x => x.Id == paidLoanModel.Id);
            }

            paidLoan.LoanId    = paidLoanModel.LoanId;
            paidLoan.UserId    = paidLoanModel.EmployeeId;
            paidLoan.AccountId = paidLoanModel.AccountId;
            paidLoan.Date      = paidLoanModel.Date;
            paidLoan.Year      = paidLoanModel.Year;
            paidLoan.Month     = paidLoanModel.Month;
            paidLoan.Amount    = paidLoanModel.Amount;

            if (paidLoanModel.Id == 0)
            {
                FarmManagementEntities.PaidLoans.Add(paidLoan);
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, paidLoanModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Пример #4
0
        public ActionResult CreateUpdateFarmAccount(AccountViewModel accountModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var account = new Account();

            if (accountModel.Id > 0)
            {
                account = FarmManagementEntities.Accounts.Single(x => x.Id == accountModel.Id);
            }

            account.Name = accountModel.Name;

            if (accountModel.Id == 0)
            {
                account.InsertDate = DateTime.Now;
                FarmManagementEntities.Accounts.Add(account);
            }
            else
            {
                account.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, accountModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Пример #5
0
        public ActionResult CreateUpdateAnimal(AnimalModel animalModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            if (!CheckEmployeeHasBalance(animalModel.Price))
            {
                return(ShowErrorMessage(Constant.InsufficientBalance));
            }

            var animal = new Animal();

            if (animalModel.Id > 0)
            {
                animal = FarmManagementEntities.Animals.Single(x => x.Id == animalModel.Id);
            }

            animal.FarmId    = animalModel.FarmId;
            animal.VendorId  = animalModel.VendorId;
            animal.AccountId = animalModel.AccountId;

            animal.AnimalName   = animalModel.AnimalName;
            animal.PurchaseDate = Convert.ToDateTime(animalModel.PurchaseDate);
            animal.Age          = animalModel.Age;
            animal.Color        = animalModel.Color;
            animal.Description  = animalModel.Description;
            animal.FamilyName   = animalModel.FamilyName;

            animal.Category = animalModel.AnimalCategory.ToNullIfEmptyEnum <AnimalCategory>();
            animal.Sex      = animalModel.AnimalGender.ToNullIfEmptyEnum <Gender>();

            var fileUpload = ClientSession.FileUploads.Single(x => x.FileUploadGuid == animalModel.AnimalGuid && x.FileUploadName == FileUploadPath.Animal && !x.HasRemoved);

            animal.Photo = System.IO.Path.GetFileName(fileUpload.FilePath);

            if (animalModel.Id == 0)
            {
                animal.Price      = animalModel.Price;
                animal.InsertDate = DateTime.Now;
                animal.UserId     = animalModel.UserId;
                FarmManagementEntities.Animals.Add(animal);

                ManageEmployeeBalance(animalModel.Price);
            }
            else
            {
                animal.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            UpdateFileUploadPath(FileUploadPath.Animal, fileUpload, animal.Id);
            ClearAllFileUpload();

            var message = string.Format(Constant.SuccessMessage, animalModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
        public ActionResult CreateUpdatePersonalAccount(PersonalAccountModel personalAccountModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var personalAccount = new PersonalAccount();

            if (personalAccountModel.Id > 0)
            {
                personalAccount = FarmManagementEntities.PersonalAccounts.Single(x => x.Id == personalAccountModel.Id);
            }

            personalAccount.UserId         = personalAccountModel.EmployeeId;
            personalAccount.OpeningBalance = personalAccountModel.OpeningBalance;
            personalAccount.ClosingDate    = personalAccountModel.ClosingDate;
            personalAccount.CreatedDate    = personalAccountModel.CreatedDate;

            if (personalAccountModel.Id == 0)
            {
                personalAccount.InsertDate = DateTime.Now;
                FarmManagementEntities.PersonalAccounts.Add(personalAccount);
            }
            else
            {
                personalAccount.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, personalAccountModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Пример #7
0
        public ActionResult CreateUpdateSeed(SeedModel seedModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            if (!CheckEmployeeHasBalance(seedModel.TotalPricePer))
            {
                return(ShowErrorMessage(Constant.InsufficientBalance));
            }

            var seed = new Seed();

            if (seedModel.Id > 0)
            {
                seed = FarmManagementEntities.Seeds.Single(x => x.Id == seedModel.Id);
            }

            seed.FarmId    = seedModel.FarmId;
            seed.VendorId  = seedModel.VendorId;
            seed.AccountId = seedModel.AccountId;
            seed.CropId    = seedModel.CropId;

            seed.DatePurchase     = seedModel.DatePurchase;
            seed.OtherDescription = seedModel.OtherDescription;

            seed.Quality  = seedModel.SeedQuality.ToNullIfEmptyEnum <Quality>();
            seed.Quantity = seedModel.SeedQuantity.ToNullIfEmptyEnum <Quantity>();

            var fileUpload = ClientSession.FileUploads.Single(x => x.FileUploadGuid == seedModel.SeedGuid && x.FileUploadName == FileUploadPath.Seed && !x.HasRemoved);

            seed.PaymentBill = System.IO.Path.GetFileName(fileUpload.FilePath);

            if (seedModel.Id == 0)
            {
                seed.TotalPricePer    = seedModel.TotalPricePer;
                seed.PricePerItem     = seedModel.PricePerItem;
                seed.QuantityInNumber = seedModel.QuantityInNumber;

                seed.InsertDate = DateTime.Now;
                seed.UserId     = seedModel.UserId;
                FarmManagementEntities.Seeds.Add(seed);

                ManageEmployeeBalance(seedModel.TotalPricePer);
            }
            else
            {
                seed.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            UpdateFileUploadPath(FileUploadPath.Seed, fileUpload, seed.Id);
            ClearAllFileUpload();

            var message = string.Format(Constant.SuccessMessage, seedModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Пример #8
0
        public ActionResult CreateUpdatePosition(PositionModel PositionModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var Position = new Position();

            if (PositionModel.Id > 0)
            {
                Position = FarmManagementEntities.Positions.Single(x => x.Id == PositionModel.Id);
            }

            Position.Id           = PositionModel.Id;
            Position.Name         = PositionModel.Name;
            Position.DepartmentId = PositionModel.DepartmentId;
            Position.Date         = PositionModel.Date;
            Position.Description  = PositionModel.Description;

            if (PositionModel.Id == 0)
            {
                Position.Date = DateTime.Now;
                FarmManagementEntities.Positions.Add(Position);
            }

            FarmManagementEntities.SaveChanges();


            var message = string.Format(Constant.SuccessMessage, PositionModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Пример #9
0
        public ActionResult CreateUpdateOtherItemExpense(OtherExpenseModel otherItemExpenseModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var otherItemExpense = new OtherExpense();

            if (otherItemExpenseModel.Id > 0)
            {
                otherItemExpense = FarmManagementEntities.OtherExpenses.Single(x => x.Id == otherItemExpenseModel.Id);
            }

            otherItemExpense.FarmId    = otherItemExpenseModel.FarmId;
            otherItemExpense.AccountId = otherItemExpenseModel.AccountId;

            otherItemExpense.OtherItemId = otherItemExpenseModel.OtherItemId;
            otherItemExpense.Amount      = otherItemExpenseModel.Amount;
            otherItemExpense.Description = otherItemExpenseModel.Description;
            otherItemExpense.Date        = otherItemExpenseModel.Date;

            if (otherItemExpenseModel.Id == 0)
            {
                otherItemExpense.UserId = otherItemExpenseModel.UserId;
                FarmManagementEntities.OtherExpenses.Add(otherItemExpense);
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, otherItemExpenseModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
        public ActionResult CreateUpdateDepartment(DepartmentModel departmentModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var department = new Department();

            if (departmentModel.Id > 0)
            {
                department = FarmManagementEntities.Departments.Single(x => x.Id == departmentModel.Id);
            }

            department.Id          = departmentModel.Id;
            department.Name        = departmentModel.Name;
            department.Status      = departmentModel.Status;
            department.Date        = departmentModel.Date;
            department.Description = departmentModel.Description;

            if (departmentModel.Id == 0)
            {
                department.Date = DateTime.Now;
                FarmManagementEntities.Departments.Add(department);
            }

            FarmManagementEntities.SaveChanges();


            var message = string.Format(Constant.SuccessMessage, departmentModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
        public ActionResult CreateUpdateTransectionAccount(TransectionAccountModel transectionAccountModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var isPayByUserExist = FarmManagementEntities.PersonalAccounts.Any(x => x.UserId == transectionAccountModel.PayByUserId);

            if (!isPayByUserExist)
            {
                return(ShowErrorMessage("Selected Pay By employee doesn't have personal account."));
            }

            var transectionAccount = new TransectionAccount();

            transectionAccount.Id          = transectionAccountModel.Id;
            transectionAccount.UserId      = transectionAccountModel.UserId;
            transectionAccount.PayByUserId = transectionAccountModel.PayByUserId;
            transectionAccount.Balance     = transectionAccountModel.Balance;
            transectionAccount.Date        = transectionAccountModel.Date;

            var userAccount = FarmManagementEntities.TransectionPersonalAccounts.Where(x => x.UserId == transectionAccountModel.UserId)
                              .OrderByDescending(x => x.InsertDate).First();
            var userPersonalAccount = new TransectionPersonalAccount();

            userPersonalAccount.Debit          = transectionAccountModel.Balance;
            userPersonalAccount.Balance        = userAccount.Balance - transectionAccountModel.Balance;
            userPersonalAccount.Date           = transectionAccountModel.Date;
            userPersonalAccount.InsertDate     = DateTime.Now;
            userPersonalAccount.IsAddedByAdmin = false;
            userPersonalAccount.UserId         = transectionAccountModel.UserId;
            FarmManagementEntities.TransectionPersonalAccounts.Add(userPersonalAccount);


            var payByUserAccount = FarmManagementEntities.TransectionPersonalAccounts.Where(x => x.UserId == transectionAccountModel.PayByUserId)
                                   .OrderByDescending(x => x.InsertDate).FirstOrDefault();
            var payByUserPersonalAccount = new TransectionPersonalAccount();

            payByUserPersonalAccount.Credit         = transectionAccountModel.Balance;
            payByUserPersonalAccount.Balance        = (payByUserAccount == null ? 0 : payByUserAccount.Balance) + transectionAccountModel.Balance;
            payByUserPersonalAccount.Date           = transectionAccountModel.Date;
            payByUserPersonalAccount.InsertDate     = DateTime.Now;
            payByUserPersonalAccount.UserId         = transectionAccountModel.PayByUserId;
            payByUserPersonalAccount.IsAddedByAdmin = false;
            FarmManagementEntities.TransectionPersonalAccounts.Add(payByUserPersonalAccount);

            if (transectionAccountModel.Id == 0)
            {
                transectionAccount.InsertDate = DateTime.Now;
                FarmManagementEntities.TransectionAccounts.Add(transectionAccount);
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, transectionAccountModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
        public ActionResult DeleteTask(Int32 id)
        {
            var taskAssign = FarmManagementEntities.TaskAssignments.Single(x => x.Id == id);

            FarmManagementEntities.TaskAssignments.Remove(taskAssign);
            FarmManagementEntities.SaveChanges();
            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #13
0
        public ActionResult CreateUpdateFuel(FuelModel fuelModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            if (!CheckEmployeeHasBalance(fuelModel.TotalPrice))
            {
                return(ShowErrorMessage(Constant.InsufficientBalance));
            }

            var fuel = new Fuel();

            if (fuelModel.Id > 0)
            {
                fuel = FarmManagementEntities.Fuels.Single(x => x.Id == fuelModel.Id);
            }

            fuel.FarmId    = fuelModel.FarmId;
            fuel.VendorId  = fuelModel.VendorId;
            fuel.AccountId = fuelModel.AccountId;

            fuel.FuelName         = fuelModel.FuelName;
            fuel.DatePurchase     = fuelModel.DatePurchase;
            fuel.OtherDescription = fuelModel.OtherDescription;

            var fileUpload = ClientSession.FileUploads.Single(x => x.FileUploadGuid == fuelModel.FuelGuid && x.FileUploadName == FileUploadPath.Fuel &&
                                                              !x.HasRemoved);

            fuel.PaymentBill = System.IO.Path.GetFileName(fileUpload.FilePath);

            if (fuelModel.Id == 0)
            {
                fuel.TotalPrice      = fuelModel.TotalPrice;
                fuel.QuantityInLiter = fuelModel.QuantityInLiter;
                fuel.PricePerLiter   = fuelModel.PricePerLiter;

                fuel.InsertDate = DateTime.Now;
                fuel.UserId     = fuelModel.UserId;
                FarmManagementEntities.Fuels.Add(fuel);

                ManageEmployeeBalance(fuelModel.TotalPrice);
            }
            else
            {
                fuel.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            UpdateFileUploadPath(FileUploadPath.Fuel, fileUpload, fuel.Id);
            ClearAllFileUpload();

            var message = string.Format(Constant.SuccessMessage, fuelModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Пример #14
0
        public ActionResult DeleteOtherItemExpense(Int32 id)
        {
            var otherItemExpense = FarmManagementEntities.OtherExpenses.Single(x => x.Id == id);

            FarmManagementEntities.OtherExpenses.Remove(otherItemExpense);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #15
0
        public ActionResult DeleteMachinery(Int32 id)
        {
            var machinery = FarmManagementEntities.Machineries.Single(x => x.Id == id);

            FarmManagementEntities.Machineries.Remove(machinery);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #16
0
        public ActionResult DeleteTemporaryEmployeeSalary(Int32 id)
        {
            var empSalary = FarmManagementEntities.TemporaryEmployeeSalaries.Single(x => x.Id == id);

            FarmManagementEntities.TemporaryEmployeeSalaries.Remove(empSalary);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #17
0
        public ActionResult DeleteCrop(Int32 id)
        {
            var crop = FarmManagementEntities.CropManagements.Single(x => x.Id == id);

            FarmManagementEntities.CropManagements.Remove(crop);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #18
0
        public ActionResult DeleteEmployeeLoan(Int32 id)
        {
            var employeeLoan = FarmManagementEntities.LoanReceivableFromEmployees.Single(x => x.Id == id);

            FarmManagementEntities.LoanReceivableFromEmployees.Remove(employeeLoan);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
        public ActionResult DeleteTransectionPersonalAccount(Int32 id)
        {
            var transectionAccount = FarmManagementEntities.TransectionPersonalAccounts.Single(x => x.Id == id);

            FarmManagementEntities.TransectionPersonalAccounts.Remove(transectionAccount);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #20
0
        public ActionResult DeleteFertilizer(Int32 id)
        {
            var seed = FarmManagementEntities.Fertilizers.Single(x => x.Id == id);

            FarmManagementEntities.Fertilizers.Remove(seed);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
        public ActionResult DeleteDepartment(Int32 id)
        {
            var departments = FarmManagementEntities.Departments.Single(x => x.Id == id);

            FarmManagementEntities.Departments.Remove(departments);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #22
0
        public ActionResult DeleteAnimal(Int32 id)
        {
            var animal = FarmManagementEntities.Animals.Single(x => x.Id == id);

            FarmManagementEntities.Animals.Remove(animal);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #23
0
        public ActionResult DeleteFarmAccount(Int32 id)
        {
            var account = FarmManagementEntities.Accounts.Single(x => x.Id == id);

            FarmManagementEntities.Accounts.Remove(account);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #24
0
        public ActionResult DeleteFarmArea(Int32 id)
        {
            var farmArea = FarmManagementEntities.FarmAreas.Single(x => x.Id == id);

            FarmManagementEntities.FarmAreas.Remove(farmArea);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #25
0
        public ActionResult DeleteVendor(Int32 id)
        {
            var vendor = FarmManagementEntities.VendorManagements.Single(x => x.Id == id);

            FarmManagementEntities.VendorManagements.Remove(vendor);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #26
0
        public ActionResult DeletePosition(Int32 id)
        {
            var Positions = FarmManagementEntities.Positions.Single(x => x.Id == id);

            FarmManagementEntities.Positions.Remove(Positions);
            FarmManagementEntities.SaveChanges();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #27
0
        public ActionResult DeleteSeed(Int32 id)
        {
            var seed = FarmManagementEntities.Seeds.Single(x => x.Id == id);

            FarmManagementEntities.Seeds.Remove(seed);
            FarmManagementEntities.SaveChanges();

            ExtensionMethods.GetFileUploadPath(FileUploadPath.Seed.ToString(), id.ToString()).DeleteUploadFile();

            return(ShowSuccessMessage(Constant.DeletedMessage));
        }
Пример #28
0
        public ActionResult Login(UserModal userModel, string ReturnUrl)
        {
            if (!ModelState.IsValid)
            {
                this.ShowErrorMessage(Constant.DefaultErrorMessage);
                return(View());
            }

            var user = dbEntity.Users.SingleOrDefault(x => x.UserName == userModel.UserName);

            if (user == null)
            {
                this.ShowErrorMessage("Incorrect username or passsword");
                return(View());
            }

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddDays(7), userModel.RememberMe, user.UserName);
            string     hashCookies           = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);

            Response.Cookies.Add(cookie);

            user.LastLogin = DateTime.Now;
            dbEntity.SaveChanges();

            HttpCookie myCookie = new HttpCookie("FarmCookies");

            //Add key-values in the cookie
            myCookie.Values.Add("UserId", user.Id.ToString());
            myCookie.Values.Add("Role", user.RoleId.ToString());
            myCookie.Values.Add("IsAdmin", user.IsAdmin.ToString());

            //set cookie expiry date-time. Made it to last for next 12 hours.
            myCookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(myCookie);

            LoggedInUser.Name    = user.Name;
            LoggedInUser.UserId  = user.Id;
            LoggedInUser.IsAdmin = user.IsAdmin;
            LoggedInUser.RoleId  = user.RoleId;

            var baseController = new BaseController();

            baseController.GetFormSetting();

            if (!string.IsNullOrEmpty(ReturnUrl))
            {
                return(Redirect(ReturnUrl));
            }

            return(RedirectToAction("Dashboard", "Home"));
        }
Пример #29
0
        public ActionResult CreateUpdatePermanentEmployeeSalary(PermanentEmployeeSalaryModel empModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var empSalary = new PermanentEmployeeSalary();

            if (empModel.Id > 0)
            {
                empSalary = FarmManagementEntities.PermanentEmployeeSalaries.Single(x => x.Id == empModel.Id);
            }

            empSalary.Year             = empModel.Year;
            empSalary.Month            = empModel.Month;
            empSalary.Date             = empModel.Date;
            empSalary.UserId           = empModel.EmployeeId;
            empSalary.BasicSalary      = empModel.BasicSalary;
            empSalary.MedicalAllowance = Convert.ToDecimal(empModel.MedicalAllowance);
            empSalary.TA_DA            = Convert.ToDecimal(empModel.TA_DA);
            empSalary.HouseRent        = Convert.ToDecimal(empModel.HouseRent);
            empSalary.UtilityAllowance = Convert.ToDecimal(empModel.UtilityAllowance);
            empSalary.ProvidentFund    = Convert.ToDecimal(empModel.ProvidentFund);
            empSalary.Bonus            = Convert.ToDecimal(empModel.Bonus);
            empSalary.Penality         = empModel.Penality;
            empSalary.IsAllowFund      = empModel.IsAllowFund;

            if (empModel.Id == 0)
            {
                empSalary.InsertDate = DateTime.Now;
                FarmManagementEntities.PermanentEmployeeSalaries.Add(empSalary);
            }
            else
            {
                empSalary.UpdateDate = DateTime.Now;
            }

            var user = FarmManagementEntities.Users.FirstOrDefault(u => u.Id == empModel.EmployeeId);

            if (user != null)
            {
                user.Salary = empModel.BasicSalary.ToString();
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, empModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
        public ActionResult CreateUpdateLoanManagement(LoanManagementModel loanManagementModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var loanManagement = new LoanManagement();

            if (loanManagementModel.Id > 0)
            {
                loanManagement = FarmManagementEntities.LoanManagements.Single(x => x.Id == loanManagementModel.Id);
            }

            loanManagement.UserId          = loanManagementModel.EmployeeId;
            loanManagement.LoanAmount      = loanManagementModel.LoanAmount;
            loanManagement.NoOfInstallment = loanManagementModel.NoOfInstallment;
            loanManagement.PerMonthOrYear  = loanManagementModel.PerMonthOrYear;
            loanManagement.LoanStartDate   = loanManagementModel.LoanStartDate;
            loanManagement.LoanEndDate     = loanManagementModel.LoanEndDate;
            loanManagement.IntersetRate    = Convert.ToDecimal(loanManagementModel.IntersetRate);
            loanManagement.Description     = loanManagementModel.Description;
            loanManagement.DebtSalary      = loanManagementModel.DebtSalary;

            loanManagement.DeductedSalary = "0";

            //if (loanManagement.DebtSalary != null && (bool)loanManagement.DebtSalary)
            //{
            //    if (loanManagement.User.Salary != null)
            //        loanManagement.DeductedSalary = ((loanManagementModel.LoanAmount - decimal.Parse(loanManagement.User.Salary)) * 1).ToString();
            //}

            loanManagement.Status = loanManagementModel.LoanStatus.ToNullIfEmptyEnum <LoanStatus>();

            if (loanManagementModel.Id == 0)
            {
                loanManagement.InsertDate = DateTime.Now;
                FarmManagementEntities.LoanManagements.Add(loanManagement);
            }
            else
            {
                loanManagement.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, loanManagementModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }