Example #1
0
        public PersonInsertResponse Insert(PersonInsertRequest request)
        {
            var response = new PersonInsertResponse();

            if (request.IsNotValid())
            {
                response.Message = ConstHelper.REQUEST_NOT_VALID;
                return(response);
            }

            try
            {
                var entity = PersonMapper.MapEntityFromRequest(request);
                _personRepository.Insert(entity);

                var model = PersonMapper.MapModelFromEntity(entity);
                response.Model = model;
            }
            catch (Exception ex)
            {
                response.Message = string.Format("Insert to database failed!{0}{1}", Environment.NewLine, ex.Message);
                return(response);
            }

            response.Status  = true;
            response.Message = "Person inserted.";
            return(response);
        }
Example #2
0
        public PersonUpdateResponse Update(PersonUpdateRequest request)
        {
            var response = new PersonUpdateResponse();

            if (request.IsNotValid())
            {
                response.Message = ConstHelper.REQUEST_NOT_VALID;
                return(response);
            }

            try
            {
                var entity = _personRepository.SelectOne(request.UId);
                if (entity == null)
                {
                    response.Message = "There is no entity with this uid!";
                    return(response);
                }

                PersonMapper.MapEntityFromRequest(request, entity);
                var result = _personRepository.Update(entity);

                if (result.ModifiedCount != 1)
                {
                    response.Message = "Update could not be done!";
                    return(response);
                }

                var model = PersonMapper.MapModelFromEntity(entity);
                response.Model = model;

                var cacheKey = "Person-" + request.UId;
                CacheManager.AddOrUpdateItem(cacheKey, model);
            }
            catch (Exception ex)
            {
                response.Message = string.Format("Update entity failed on database process!{0}{1}", Environment.NewLine, ex.Message);
                return(response);
            }

            response.Status  = true;
            response.Message = "Person updated.";
            return(response);
        }