Ejemplo n.º 1
0
        // POST: api/Banner
        public HttpResponseMessage Post([FromBody] AdminProjectVMInput AdminProjectVMInput)
        {
            try
            {
                if (AdminProjectVMInput.ResourceUrl.ToString() != "")
                {
                    if (AdminProjectVMInput.ResourceUrl.ToString().Contains("/Content"))
                    {
                        AdminProjectVMInput.ResourceUrl = AdminProjectVMInput.ResourceUrl;
                        AdminProjectVMInput.Thumbnail = AdminProjectVMInput.Thumbnail;
                    }
                    else
                    {
                        AdminProjectVMInput.Thumbnail = "/Content/UploadFiles/images/images/thumb_" + AdminProjectVMInput.ResourceUrl;
                        AdminProjectVMInput.ResourceUrl = "/Content/UploadFiles/images/images/" + AdminProjectVMInput.ResourceUrl;
                    }
                }
                else
                {
                    AdminProjectVMInput.ResourceUrl = "/Content/images/No_image_available.png";
                    AdminProjectVMInput.Thumbnail = "/Content/images/No_image_available.png";
                }

                var name = AdminProjectVMInput.Name;
                var intro = AdminProjectVMInput.Intro;
                var keyword = AdminProjectVMInput.Keyword;
                var description = AdminProjectVMInput.Description;
                var detail = AdminProjectVMInput.Detail;
                var metaData = AdminProjectVMInput.MetaData;
                var thumbnail = AdminProjectVMInput.Thumbnail;
                var resourceUrl = AdminProjectVMInput.ResourceUrl;

                var maxOrder = _projectService.Entities.Where(p => p.Type == 1 && p.Deleted == false).Max(p => p.ZOrder);

                var projectModel = new Project()
                {
                    Name = name, Type = 1, ZOrder = maxOrder + 1, Status = true, Deleted = false,
                    CreatedById = _userId, ModifiedById = _userId
                };
                _projectService.Add(projectModel);

                var justAddedProjectId = _projectService.Entities.Max(b => b.Id);

                /*
                 add project image
                 */

                var projectImage = new ProjectImage()
                {
                    ProjectId = justAddedProjectId, Thumbnail = thumbnail, ResourceUrl = resourceUrl,
                    Type = 1, ZOrder = 1, Status = true, Deleted = false,
                    CreatedById = _userId, ModifiedById = _userId
                };
                _projectImageService.Add(projectImage);

                var justAddedProjectImageId = _projectImageService.Entities.Max(b => b.Id);
                var projectImageMappingList = new List<ProjectImageMapping>()
                {
                    new ProjectImageMapping()
                    {
                        ProjectImageId = justAddedProjectImageId, LanguageId = 129, Deleted = false, Status = true,
                        Name = name, Description = "",
                        CreatedById = _userId, ModifiedById = _userId
                    },
                    new ProjectImageMapping()
                    {
                        ProjectImageId = justAddedProjectImageId, LanguageId = 29, Deleted = false, Status = true,
                        Name = name + " - EN", Description = "",
                        CreatedById = _userId, ModifiedById = _userId
                    }
                };
                foreach (var pim in projectImageMappingList)
                {
                    _projectImageMappingService.Add(pim);
                }

                /*
                 Add News
                 */

                var news = new News();
                news.ProjectId = justAddedProjectId;
                news.Name = AdminProjectVMInput.Name;
                news.CreatedById = _userId;
                news.ModifiedById = _userId;
                news.Deleted = false;
                news.Status = true;
                news.ZOrder = 1;
                _newsService.Add(news);

                var justAddedNewsId = _newsService.Entities.Max(b => b.Id);
                var newsMappingsModels = new List<NewsMapping>()
                {
                    new NewsMapping()
                    {
                        NewsId = justAddedNewsId, LanguageId = 129, Status = true, Deleted = false,
                        Title = news.Name, Intro = intro, Keyword = keyword, Description = description, MetaData = metaData, Detail = detail,
                        CreatedById = _userId, ModifiedById = _userId,
                    },
                    new NewsMapping()
                    {
                        NewsId = justAddedNewsId, LanguageId = 29, Status = true,
                        Title = "", Intro = "", Keyword = "", Description = "", Deleted = false, Detail = "", MetaData = "",
                        CreatedById = _userId, ModifiedById = _userId
                    }
                };
                foreach (var nm in newsMappingsModels)
                {
                    _newsMappingService.Add(nm);
                }

                var responseMessage = new { message = "Thêm thành công!" };
                return Request.CreateResponse(HttpStatusCode.OK, responseMessage);
            }
            catch (Exception)
            {
                var responseMessage = new { message = "Lỗi! Vui lòng thử lại sau!" };
                return Request.CreateResponse(HttpStatusCode.InternalServerError, responseMessage);
                throw;
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post([FromBody]AdminProjectImageVMInput AdminProjectImageVMInput)
        {
            try
            {
                if (AdminProjectImageVMInput.ResourceUrl.ToString() != "")
                {
                    if (AdminProjectImageVMInput.ResourceUrl.ToString().Contains("/Content"))
                    {
                        AdminProjectImageVMInput.ResourceUrl = AdminProjectImageVMInput.ResourceUrl;
                        AdminProjectImageVMInput.Thumbnail = AdminProjectImageVMInput.Thumbnail;
                    }
                    else
                    {
                        AdminProjectImageVMInput.Thumbnail = "/Content/UploadFiles/images/images/thumb_" + AdminProjectImageVMInput.ResourceUrl;
                        AdminProjectImageVMInput.ResourceUrl = "/Content/UploadFiles/images/images/" + AdminProjectImageVMInput.ResourceUrl;
                    }
                }
                else
                {
                    AdminProjectImageVMInput.ResourceUrl = "/Content/images/No_image_available.png";
                    AdminProjectImageVMInput.Thumbnail = "/Content/images/No_image_available.png";
                }

                var maxZOrder = _projectImageService.Entities.Where(b => b.ProjectId == AdminProjectImageVMInput.ProjectId).Max(b => b.ZOrder);

                var projectImageModel = new ProjectImage();
                projectImageModel.ProjectId = AdminProjectImageVMInput.ProjectId;
                projectImageModel.ResourceUrl = AdminProjectImageVMInput.ResourceUrl;
                projectImageModel.Thumbnail = AdminProjectImageVMInput.Thumbnail;
                projectImageModel.ZOrder = maxZOrder;
                projectImageModel.Status = true;
                projectImageModel.CreatedById = _userId;
                projectImageModel.CreatedDateTime = DateTime.Now;
                projectImageModel.ModifiedDateTime = DateTime.Now;
                projectImageModel.ModifiedById = _userId;

                _projectImageService.Add(projectImageModel);

                var justAddedProjectImageId = _projectImageService.Entities.Max(b => b.Id);
                var projectImageMappingsList = new List<ProjectImageMapping>()
                {
                    new ProjectImageMapping()
                    {
                        ProjectImageId = justAddedProjectImageId, LanguageId = 129, Status = true, Deleted = false,
                        Name = AdminProjectImageVMInput.Name, Description = AdminProjectImageVMInput.Description,
                        CreatedById = _userId, ModifiedById = _userId,
                        CreatedDateTime = DateTime.Now, ModifiedDateTime = DateTime.Now
                    },
                    new ProjectImageMapping()
                    {
                        ProjectImageId = justAddedProjectImageId, LanguageId = 29, Status = true, Deleted = false,
                        Name = "", Description = "",
                        CreatedById = _userId, ModifiedById = _userId,
                        CreatedDateTime = DateTime.Now, ModifiedDateTime = DateTime.Now
                    }
                };
                foreach (var im in projectImageMappingsList)
                {
                    _projectImageMappingService.Add(im);
                }

                var responseMessage = new { message = "Chỉnh sửa thành công!" };
                return Request.CreateResponse(HttpStatusCode.OK, responseMessage);
            }
            catch (Exception)
            {
                var responseMessage = new { message = "Lỗi! Vui lòng thử lại sau!" };
                return Request.CreateResponse(HttpStatusCode.InternalServerError, responseMessage);
                throw;
            }
        }
Ejemplo n.º 3
0
        // POST: api/Banner
        public HttpResponseMessage Post([FromBody] AdminVideoVMInput adminVideoVMInput)
        {
            try
            {
                if (adminVideoVMInput.Thumbnail.ToString() != "")
                {
                    if (adminVideoVMInput.Thumbnail.ToString().Contains("/Content"))
                    {
                        adminVideoVMInput.Thumbnail = adminVideoVMInput.Thumbnail;
                    }
                    else
                    {
                        adminVideoVMInput.Thumbnail = "/Content/UploadFiles/images/images/thumb_" + adminVideoVMInput.Thumbnail;
                    }

                }
                else
                    adminVideoVMInput.Thumbnail = "/Content/images/No_image_available.png";

                var name = adminVideoVMInput.Name;
                var description = adminVideoVMInput.Description;
                var thumbnail = adminVideoVMInput.Thumbnail;
                var resourceUrl = adminVideoVMInput.ResourceUrl;

                var maxOrder =  _projectImageService.Entities.Where(p => p.Deleted == false && p.Type == 2).Max(p => p.ZOrder);

                var projectImageModel = new ProjectImage()
                {
                    ProjectId = 15,
                    Thumbnail = thumbnail,
                    ResourceUrl = resourceUrl,
                    Deleted = false,
                    Status = true,
                    CreatedById = _userId,
                    ModifiedById = _userId,
                    CreatedDateTime = DateTime.Now,
                    ModifiedDateTime = DateTime.Now,
                    Type = 2,
                    ZOrder = maxOrder + 1
                };

                _projectImageService.Add(projectImageModel);

                var justAddedImageId = _projectImageService.Entities.Where(p => p.Deleted == false && p.Type == 2).Max(p => p.Id);

                var currentVideoLanguage = adminVideoVMInput.CurrentImageMapping;

                var projectImageMappingList = new List<ProjectImageMapping>()
                {
                    new ProjectImageMapping()
                    {
                        ProjectImageId = justAddedImageId,
                        LanguageId = 129,
                        Status = true,
                        Deleted = false,
                        Name = name,
                        Description = description,
                        CreatedById = _userId,
                        CreatedDateTime = DateTime.Now,
                        ModifiedById = _userId,
                        ModifiedDateTime = DateTime.Now
                    },
                    new ProjectImageMapping()
                    {
                        ProjectImageId = justAddedImageId,
                        LanguageId = 29,
                        Status = true,
                        Deleted = false,
                        Name = name + " - EN",
                        Description = "",
                        CreatedById = _userId,
                        CreatedDateTime = DateTime.Now,
                        ModifiedById = _userId,
                        ModifiedDateTime = DateTime.Now
                    }
                };

                foreach (var pim in projectImageMappingList)
                {
                    _projectImageMappingService.Add(pim);
                }

                var responseMessage = new { message = "Chỉnh sửa thành công!" };
                return Request.CreateResponse(HttpStatusCode.OK, responseMessage);
            }
            catch (Exception)
            {
                var responseMessage = new { message = "Lỗi! Vui lòng thử lại sau!" };
                return Request.CreateResponse(HttpStatusCode.InternalServerError, responseMessage);
                throw;
            }
        }