public DataResponse <EntityMarketing> Update(EntityMarketing entity)
        {
            var response = new DataResponse <EntityMarketing>();

            try
            {
                base.DBInit();
                var model = DBEntity.MarketingDocuments.FirstOrDefault(a => a.Id == entity.Id);

                model.Name           = entity.Name;
                model.Description    = entity.Description;
                model.DocumentTypeId = entity.DocumentTypeId;
                model.CategoryId     = entity.CategoryId;
                model.UpdatedBy      = entity.CurrentUserId;
                model.UpdatedOn      = System.DateTime.UtcNow;
                if (DBEntity.SaveChanges() > 0)
                {
                    return(GetMarketingById(model.Id, entity.CurrentUserId, entity.BusinessId));
                }
                else
                {
                    response.CreateResponse(DataResponseStatus.InternalServerError);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }
        public IHttpActionResult InsertMarketingData(EntityMarketing model)
        {
            var response = new DataResponse <EntityMarketing>();

            if (ModelState.IsValid)
            {
                model.UpdatedBy = model.CreatedBy = model.CurrentUserId = CurrentUserId;
                //model.CategoryId = 1;
                model.CreatedOn  = System.DateTime.UtcNow;
                model.BusinessId = CurrentBusinessId;
                if (model.Id > 0)
                {
                    response = new RepositoryMarketing().Update(model);
                }
                else
                {
                    response = new RepositoryMarketing().Insert(model);
                }

                #region Upload file

                if (model.Files != null && model.Files.Count > 0)
                {
                    List <string> FilesList   = new List <string>();
                    int           MarketingId = response.Model.Id;

                    foreach (var file in model.Files)
                    {
                        string FileName = SaveFile(file.Base64, file.FileName, MarketingId);
                        FilesList.Add(FileName);
                    }

                    bool isImagesSaved = new RepositoryMarketing().SaveFiles(FilesList, MarketingId, model.Id > 0, CurrentUserId);
                }

                #endregion

                return(Ok <DataResponse>(response));
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
        }
        public DataResponse <EntityMarketing> Insert(EntityMarketing entity)
        {
            var response = new DataResponse <EntityMarketing>();

            try
            {
                base.DBInit();

                var model = new Database.MarketingDocument
                {
                    Name           = entity.Name,
                    DocumentTypeId = entity.DocumentTypeId,
                    Description    = entity.Description,
                    //Url=entity.Url,
                    CategoryId = entity.CategoryId,
                    CreatedOn  = entity.CreatedOn,
                    CreatedBy  = entity.CreatedBy,
                    BusinessId = entity.BusinessId,
                };

                if (base.DBSave(model) > 0)
                {
                    entity.Id = model.Id;

                    response.CreateResponse <EntityMarketing>(entity, DataResponseStatus.OK);
                }
                else
                {
                    response.CreateResponse(DataResponseStatus.InternalServerError);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }