Пример #1
0
        public ActionResult Details(int id)
        {
            ServiceModel service = _serviceService.Find(id);

            service.TagList      = _tagService.DropDownList(service.TagIds);
            service.CategoryList = _categoryService.DropDownList(service.CategoryIds);
            return(View(service));
        }
Пример #2
0
        public async Task <IHttpActionResult> Updateservice(int?se_id)
        {
            ResponseDataDTO <service> response = new ResponseDataDTO <service>();

            try
            {
                var path = Path.GetTempPath();

                if (!Request.Content.IsMimeMultipartContent("form-data"))
                {
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
                }

                MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(path);

                await Request.Content.ReadAsMultipartAsync(streamProvider);

                // save file
                string fileName = "";
                if (streamProvider.FileData.Count > 0)
                {
                    foreach (MultipartFileData fileData in streamProvider.FileData)
                    {
                        fileName = FileExtension.SaveFileOnDisk(fileData);
                    }
                }

                // get data from formdata
                ServiceUpdateViewModel serviceUpdateViewModel = new ServiceUpdateViewModel
                {
                    se_id          = Convert.ToInt32(streamProvider.FormData["se_id"]),
                    se_code        = Convert.ToString(streamProvider.FormData["se_code"]),
                    se_name        = Convert.ToString(streamProvider.FormData["se_name"]),
                    se_description = Convert.ToString(streamProvider.FormData["se_description"]),



                    service_category_id = Convert.ToInt32(streamProvider.FormData["service_category_id"]),
                    se_price            = Convert.ToInt32(streamProvider.FormData["se_price"]),
                    se_saleoff          = Convert.ToInt32(streamProvider.FormData["se_saleoff"]),

                    se_type = Convert.ToByte(streamProvider.FormData["se_type"]),
                };


                var existservice = _serviceservice.Find(se_id);

                if (fileName != "")
                {
                    serviceUpdateViewModel.se_thumbnai = fileName;
                }
                else
                {
                    serviceUpdateViewModel.se_thumbnai = existservice.se_thumbnai;
                }

                // mapping view model to entity
                var updatedservice = _mapper.Map <service>(serviceUpdateViewModel);



                // update service
                _serviceservice.Update(updatedservice, se_id);

                // return response
                response.Code    = HttpCode.OK;
                response.Message = MessageResponse.SUCCESS;
                response.Data    = updatedservice;
                return(Ok(response));
            }
            catch (Exception ex)
            {
                response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                response.Message = ex.Message;
                response.Data    = null;
                Console.WriteLine(ex.ToString());

                return(Ok(response));
            }
        }