示例#1
0
        public POA_DELEGATIONDto SavePoaDelegation(PoaDelegationSaveInput input)
        {
            //ValidateWasteStock(input);

            POA_DELEGATION dbData = null;

            if (input.PoaDelegationDto.POA_DELEGATION_ID > 0)
            {
                //update
                dbData = _repository.GetByID(input.PoaDelegationDto.POA_DELEGATION_ID);
                if (dbData == null)
                {
                    throw new BLLException(ExceptionCodes.BLLExceptions.DataNotFound);
                }

                //set changes history
                var origin = Mapper.Map <POA_DELEGATIONDto>(dbData);

                SetChangesHistory(origin, input.PoaDelegationDto, input.UserId);

                Mapper.Map(input.PoaDelegationDto, dbData);

                dbData.MODIFIED_DATE = DateTime.Now;
                dbData.MODIFIED_BY   = input.UserId;
            }
            else
            {
                input.PoaDelegationDto.CREATED_DATE = DateTime.Now;
                input.PoaDelegationDto.CREATED_BY   = input.UserId;
                dbData = new POA_DELEGATION();
                Mapper.Map(input.PoaDelegationDto, dbData);
                _repository.Insert(dbData);
            }

            try
            {
                _uow.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }


            return(Mapper.Map <POA_DELEGATIONDto>(dbData));
        }
        private POA_DELEGATIONDto SavePoaDelegationToDatabase(PoaDelegationFormViewModel model)
        {
            var dataToSave = Mapper.Map <POA_DELEGATIONDto>(model);

            var input = new PoaDelegationSaveInput()
            {
                PoaDelegationDto = dataToSave,
                UserId           = CurrentUser.USER_ID,
                UserRole         = CurrentUser.UserRole,
            };

            return(_poaDelegationBll.SavePoaDelegation(input));
        }