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); }
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); }
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); }
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); }
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); }