Пример #1
0
        public ActionResult AddNewVehicleFuel(AddVehicleFuelViewModel model)
        {
            if (ModelState.IsValid)
            {
                var VehicleFuel = new VehicleFuelMD();
                VehicleFuel.Date        = model.Date;
                VehicleFuel.Amount      = model.Amount;
                VehicleFuel.VehicleId   = model.VehicleId;
                VehicleFuel.EmployeeId  = model.EmployeeId;
                VehicleFuel.CreatedById = Convert.ToInt32(User.Identity.GetUserId());
                VehicleFuel.CreatedDate = DateTime.Now;

                var result = _vehiclefuelService.AddVehicleFuel(VehicleFuel);
                if (!result.HasErrors)
                {
                    return(RedirectToAction("ViewAllVehicleFuels"));
                }
                else
                {
                    model.HasErrorMessage = result.HasErrors;
                    model.MessageType     = result.ResultMessages.FirstOrDefault().MessageType;
                    model.Message         = result.ResultMessages.FirstOrDefault().Message;
                    return(View(model));
                }
            }
            return(RedirectToAction("AddNewVehicleFuel"));
        }
Пример #2
0
        public static VehicleFuelMD Translate(this VehicleFuelDE from)
        {
            var to = new VehicleFuelMD();

            to.Id          = from.Id;
            to.Date        = from.Date;
            to.Amount      = from.Amount;
            to.EmployeeId  = from.EmployeeId.Value;
            to.VehicleId   = from.VehicleId;
            to.CreatedById = from.CreatedById;
            to.CreatedDate = from.CreatedDate;
            to.IsActive    = from.IsActive;
            return(to);
        }
Пример #3
0
        public ActionResult UpdateVehicleFuel(int id)
        {
            var VehicleFuel = new VehicleFuelMD();

            if (id > 0)
            {
                var result = _vehiclefuelService.GetVehicleFuelById(id);
                if (!result.HasErrors)
                {
                    VehicleFuel = result;
                    return(View(VehicleFuel));
                }
            }
            return(View(VehicleFuel));
        }
Пример #4
0
        public VehicleFuelMD AddVehicleFuel(VehicleFuelMD mod)
        {
            try
            {
                var entity = mod.Translate();
                _VehicleFuelRepo.Insert(entity);
                _VehicleFuelRepo.CommitAllChanges();
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_ADD, "VehicleFuel"));
                mod.Id = entity.Id;
            }
            catch (Exception ex)
            {
                mod.AddErrorMessage(string.Format(AppConstants.CRUD_ADD_ERROR, "VehicleFuel"));
            }

            return(mod);
        }
Пример #5
0
        public VehicleFuelMD ModifyVehicleFuel(VehicleFuelMD mod)
        {
            var entity = mod.Translate();

            try
            {
                _VehicleFuelRepo.Update(entity);
                _VehicleFuelRepo.CommitAllChanges();
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE, "VehicleFuel"));
            }
            catch (Exception)
            {
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE_ERROR, "VehicleFuel"));
            }

            return(mod);
        }
Пример #6
0
        public VehicleFuelMD DeleteVehicleFuel(long id)
        {
            var mod = new VehicleFuelMD();

            try
            {
                var VehicleFuel = _VehicleFuelRepo.Fetch(x => x.IsActive);
                VehicleFuel.IsActive = false;
                _VehicleFuelRepo.Update(VehicleFuel);
                _VehicleFuelRepo.CommitAllChanges();

                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_DELETE, "VehicleFuel"));
            }
            catch (Exception ex)
            {
                mod.AddErrorMessage(string.Format(AppConstants.CRUD_DELETE_ERROR, "VehicleFuel"));
            }
            return(mod);
        }
Пример #7
0
        public static List <VehicleFuelMD> Translate(this List <VehicleFuelDE> list)
        {
            var vehiclefuels = new List <VehicleFuelMD>();

            foreach (var from in list)
            {
                var to = new VehicleFuelMD();
                to.Id          = from.Id;
                to.Date        = from.Date;
                to.Amount      = from.Amount;
                to.EmployeeId  = from.EmployeeId.Value;
                to.VehicleId   = from.VehicleId;
                to.CreatedById = from.CreatedById;
                to.CreatedDate = from.CreatedDate;
                to.IsActive    = from.IsActive;

                vehiclefuels.Add(to);
            }
            return(vehiclefuels);
        }
Пример #8
0
 public ActionResult UpdateVehicleFuel(VehicleFuelMD model)
 {
     if (ModelState.IsValid)
     {
         var result = _vehiclefuelService.ModifyVehicleFuel(model);
         if (!result.HasErrors)
         {
             return(RedirectToAction("ViewAllVehicleFuels"));
         }
         model.HasErrors = result.HasErrors;
         model.ResultMessages.Add(result.ResultMessages.FirstOrDefault());
     }
     if (!model.HasErrors)
     {
         ResultMessage rs = new ResultMessage();
         rs.MessageType = ResultCode.Danger.ToString();
         rs.Message     = "Unable to update VehicleFuel";
         model.ResultMessages.Add(rs);
     }
     return(View(model));
 }
Пример #9
0
        public static VehicleFuelDE Translate(this VehicleFuelMD from, VehicleFuelDE dest = null)
        {
            var to = dest ?? new VehicleFuelDE();

            if (to.Id <= 0)
            {
                to.Id       = from.Id;
                to.IsActive = true;
            }
            else
            {
                to.IsActive = from.IsActive;
            }
            to.Date        = from.Date;
            to.Amount      = from.Amount;
            to.EmployeeId  = from.EmployeeId;
            to.VehicleId   = from.VehicleId;
            to.CreatedById = from.CreatedById;
            to.CreatedDate = from.CreatedDate;

            return(to);
        }