Beispiel #1
0
        public ResultDTO UpdateState(int StateId, BusinessEntities.StateEntity StateEntity)
        {
            var result = new ResultDTO {
                IsSuccess = false
            };

            if (StateEntity != null)
            {
                using (var scope = new TransactionScope())
                {
                    var stateent = _unitOfWork.StateRepository.GetByID(StateId);
                    if (stateent != null)
                    {
                        stateent.StateId    = StateEntity.StateId;
                        stateent.StateName  = StateEntity.StateName;
                        stateent.CountryId  = StateEntity.CountryId;
                        stateent.IsActive   = StateEntity.IsActive;
                        stateent.ModifiedBy = StateEntity.ModifiedBy;
                        stateent.ModifiedOn = DateTime.Now;



                        _unitOfWork.StateRepository.Update(stateent);
                        _unitOfWork.Save();
                        scope.Complete();

                        result.IsSuccess = true;
                        result.Message   = "Updated State Successfully";
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        public ResultDTO CreateState(BusinessEntities.StateEntity StateEntity)
        {
            var result = new ResultDTO {
                IsSuccess = false
            };

            var isExist = _unitOfWork.StateRepository.GetManyQueryable(c => c.StateName.ToLower() == StateEntity.StateName.ToLower() && c.CountryId == StateEntity.CountryId).Count() > 0;

            if (!isExist)
            {
                using (var scope = new TransactionScope())
                {
                    var State = new State
                    {
                        StateName  = StateEntity.StateName,
                        CountryId  = StateEntity.CountryId,
                        IsActive   = true,
                        CreatedBy  = StateEntity.CreatedBy,
                        CreatedOn  = DateTime.Now,
                        ModifiedBy = StateEntity.CreatedBy,
                        ModifiedOn = DateTime.Now,
                    };
                    _unitOfWork.StateRepository.Insert(State);
                    _unitOfWork.Save();
                    scope.Complete();

                    result.IsSuccess = true;
                    result.Message   = "Inserted State Successfully";
                }
            }
            else
            {
                result.IsSuccess = false;
                result.Message   = "State name already exist";
            }

            return(result);
        }