Esempio n. 1
0
        public Response <ArticleFavoriteModel> Create(ArticleFavoriteModel modelToCreate)
        {
            var response = InitErrorResponse();

            if (Validate(modelToCreate))
            {
                try
                {
                    var en = GetEntityFromModel(modelToCreate);
                    en.UserId      = en.CreatedById = en.UpdatedById = GetUserId();
                    en.CreatedDate = en.UpdatedDate = DateTime.UtcNow;
                    _unitOfWork.ArticleFavoriteRepository.Add(en);
                    _unitOfWork.Commit();
                    response      = InitSuccessResponse(MessageConstant.Create);
                    response.Item = GetModelFromEntity(en);
                }
                catch (Exception ex)
                {
                    response.Message = ex.Message;
                }
            }
            else
            {
                response.Message = MessageConstant.ValidationError;
            }
            return(response);
        }
Esempio n. 2
0
        public Response <ArticleCategoryModel> Create(ArticleCategoryModel modelToCreate)
        {
            var response = InitErrorResponse();

            if (Validate(modelToCreate))
            {
                try
                {
                    var en = GetEntityFromModel(modelToCreate);
                    _unitOfWork.ArticleCategoryRepository.Add(en);
                    _unitOfWork.Commit();
                    response      = InitSuccessResponse(MessageConstant.Create);
                    response.Item = GetModelFromEntity(en);
                }
                catch (Exception ex)
                {
                    response.Message = ex.Message;
                }
            }
            else
            {
                response.Message = MessageConstant.ValidationError;
            }
            return(response);
        }
Esempio n. 3
0
        public Response <FirebaseUserMapModel> Create(FirebaseUserMapModel modelToCreate)
        {
            var response = InitErrorResponse();

            if (Validate(modelToCreate))
            {
                var en = GetEntityFromModel(modelToCreate);
                en.UserId = this.GetUserId();
                var existing = _unitOfWork.FirebaseUserMapRepository.GetSingle(x => x.UserId == en.UserId &&
                                                                               x.DeviceId == modelToCreate.DeviceId);
                if (existing == null)
                {
                    _unitOfWork.FirebaseUserMapRepository.Add(this.RemoveChildEntity(en));
                    _unitOfWork.Commit();
                    response = InitSuccessResponse(MessageConstant.Create);
                }
                else
                {
                    en             = existing;
                    en.DeviceToken = modelToCreate.DeviceToken;
                    _unitOfWork.FirebaseUserMapRepository.Edit(this.RemoveChildEntity(en));
                    _unitOfWork.Commit();
                    response = InitSuccessResponse(MessageConstant.Update);
                }

                response.Item = GetModelFromEntity(en);
            }
            else
            {
                response.Message = MessageConstant.ValidationError;
            }
            return(response);
        }
Esempio n. 4
0
        public Response <ErrorLogModel> Create(ErrorLogModel modelToCreate)
        {
            var response = InitErrorResponse();

            var en = GetEntityFromModel(modelToCreate);

            _unitOfWork.ErrorLogRepository.Add(en);
            _unitOfWork.Commit();

            response      = InitSuccessResponse(MessageConstant.Create);
            response.Item = GetModelFromEntity(en);
            return(response);
        }
Esempio n. 5
0
        public Response <AdvertisingModel> Create(AdvertisingModel modelToCreate)
        {
            var response = InitErrorResponse();

            if (Validate(modelToCreate))
            {
                var userId = this.GetUserId();
                var en     = GetEntityFromModel(modelToCreate);
                en.CreatedById = en.UpdatedById = userId;
                en.CreatedDate = en.UpdatedDate = DateTime.UtcNow;
                _unitOfWork.AdvertisingRepository.Add(this.RemoveChildEntity(en));
                _unitOfWork.Commit();
                response      = InitSuccessResponse(MessageConstant.Create);
                response.Item = GetModelFromEntity(en);
            }
            else
            {
                response.Message = MessageConstant.ValidationError;
            }

            return(response);
        }