示例#1
0
        /// <summary>
        /// Created by Ashwait Bansod for Saving data to database and also update data to database
        /// </summary>
        /// <param name="objeFleetDriverModel"></param>
        /// <returns></returns>
        public eFleetDriverModel SaveEfleetDriver(eFleetDriverModel objeFleetDriverModel)
        {
            try
            {
                var objLocationMaster         = new LocationMaster();
                var objeFleetDriver           = new eFleetDriver();
                var objeFleetDriverRepository = new eFleetDriverRepository();
                var objeTracLoginModel        = new eTracLoginModel();

                if (objeFleetDriverModel.DriverID == 0)
                {
                    AutoMapper.Mapper.CreateMap <eFleetDriverModel, eFleetDriver>();
                    var objfleetDriverMapper = AutoMapper.Mapper.Map(objeFleetDriverModel, objeFleetDriver);
                    objeFleetDriverRepository.Add(objfleetDriverMapper);
                    //objeFleetDriver.QRCCodeID = objeFleetDriverModel.QRCCodeID + "EFD" + (objeFleetDriver.DriverID + 100).ToString();
                    objeFleetDriverRepository.SaveChanges();
                    objeFleetDriverModel.Result = Result.Completed;

                    if (objeFleetDriverModel.Result == Result.Completed)
                    {
                        #region Save DAR
                        DARModel objDAR = new DARModel();
                        objDAR.ActivityDetails = DarMessage.RegisterNeweFleetDriver(objeFleetDriverModel.LocationName);
                        objDAR.LocationId      = objeFleetDriverModel.LocationID;
                        objDAR.UserId          = objeFleetDriverModel.UserID;
                        objDAR.CreatedBy       = objeFleetDriverModel.UserID;
                        objDAR.CreatedOn       = DateTime.UtcNow;
                        objDAR.TaskType        = (long)TaskTypeCategory.eFleetDriverSubmission;
                        Result result = _ICommonMethod.SaveDAR(objDAR);
                        #endregion Save DAR
                    }
                }
                //edit Data
                else
                {
                    var DriverData = objeFleetDriverRepository.GetAll(v => v.IsDeleted == false && v.DriverID == objeFleetDriverModel.DriverID).FirstOrDefault();
                    if (objeFleetDriverModel.DriverImageFile != null)
                    {
                    }
                    else
                    {
                        objeFleetDriverModel.DriverImage = DriverData.DriverImage;
                    }
                    //== null ? "" : HostingPrefix + ProfilePicPath.Replace("~", "") + DriverData.DriverImage;
                    AutoMapper.Mapper.CreateMap <eFleetDriverModel, eFleetDriver>();
                    var objfleetDriverMapper = AutoMapper.Mapper.Map(objeFleetDriverModel, DriverData);
                    objeFleetDriverRepository.SaveChanges();
                    objeFleetDriverModel.Result = Result.UpdatedSuccessfully;
                    if (objeFleetDriverModel.Result == Result.UpdatedSuccessfully)
                    {
                        #region Save DAR
                        DARModel objDAR = new DARModel();
                        objDAR.ActivityDetails = DarMessage.UpdateeFleetDriver(objeFleetDriverModel.LocationName);
                        objDAR.LocationId      = objeFleetDriverModel.LocationID;
                        objDAR.UserId          = objeFleetDriverModel.UserID;
                        objDAR.ModifiedBy      = objeFleetDriverModel.UserID;
                        objDAR.ModifiedOn      = DateTime.UtcNow;
                        objDAR.TaskType        = (long)TaskTypeCategory.UpdateeFleetDriver;
                        Result result = _ICommonMethod.SaveDAR(objDAR);
                        #endregion Save DAR
                    }
                }
                return(objeFleetDriverModel);
            }
            catch (Exception ex)
            {
                Exception_B.Exception_B.exceptionHandel_Runtime(ex, "public eFleetDriverModel SaveEfleetDriver(eFleetDriverModel objeFleetDriverModel)", "Exception While saving Driver request.", objeFleetDriverModel);
                throw;
            }
        }