Пример #1
0
 public static void UpdateMaterial(this Material material, MaterialViewModel materialVm)
 {
     material.Title = materialVm.Title;
     material.Description = materialVm.Description;
     material.CategoryId = materialVm.CategoryId;
     material.Author = materialVm.Author;
     material.Content = materialVm.Content;
     material.Rating = materialVm.Rating;
     material.TrailerURI = materialVm.TrailerURI;
     material.CreateDate = materialVm.CreateDate;
 }
Пример #2
0
 public static void UpdateMaterial(this Material material, MaterialViewModel materialVm)
 {
     material.ID = new Random().Next();
     material.Title = materialVm.Title;
     material.Description = materialVm.Description;
     material.CategoryId = materialVm.CategoryId;
     material.Author = materialVm.Author;
     material.Content = materialVm.Content;
     material.Rating = 1;
     material.TrailerURI = null;
     material.Image = null;
     //material.Rating = materialVm.Rating;
     //material.TrailerURI = materialVm.TrailerURI;
     material.CreateDate = materialVm.CreateDate;
 }
Пример #3
0
        public HttpResponseMessage Update(HttpRequestMessage request, MaterialViewModel material)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var materialDB = _materialsRepository.GetSingle(material.ID);
                    if (materialDB == null)
                        response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid material.");
                    else
                    {
                        materialDB.UpdateMaterial(material);
                        material.Image = materialDB.Image;
                        _materialsRepository.Edit(materialDB);

                        _unitOfWork.Commit();
                        response = request.CreateResponse<MaterialViewModel>(HttpStatusCode.OK, material);
                    }
                }

                return response;
            });
        }
Пример #4
0
        public HttpResponseMessage Add(HttpRequestMessage request, MaterialViewModel material)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    Material newMaterial = new Material();
                    newMaterial.UpdateMaterial(material);

                    for (int i = 0; i < material.NumberOfTags; i++)
                    {
                        Tag tag = new Tag() {};
                        newMaterial.Tags.Add(tag);
                    }

                    _materialsRepository.Add(newMaterial);

                    _unitOfWork.Commit();

                    // Update view model
                    material = Mapper.Map<Material, MaterialViewModel>(newMaterial);
                    response = request.CreateResponse<MaterialViewModel>(HttpStatusCode.Created, material);
                }

                return response;
            });
        }