コード例 #1
0
        public ActionResult EditPhoto(HttpRequestMessage request, PhotoVm photo)
        {
            try
            {
                Logger.Debug("Creating photo");

                if (ModelState.IsValid)
                {
                    if (photo.Id == 0)
                    {
                        _photoRepository.EditPhoto(photo);
                    }
                    else
                    {
                        _photoRepository.Updatephoto(photo);
                    }

                    return(new JsonResult());
                }

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { validationErrors = GetErrorMessages() }));
            }
            catch (Exception ex)
            {
                var exceptionMessage = "Error creating photo";
                Logger.Error(exceptionMessage, ex);

                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Json(new { exceptionMessage }));
            }
        }
コード例 #2
0
        private void Photo_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButtonEx btn = (HyperlinkButtonEx)sender;

            string urlFormat = btn.NavigateUrlFormat;

            PhotoVm photo = (PhotoVm)btn.DataContext;

            string url = String.Format(urlFormat, String.Format("collection={0}&photoid={1}&type={2}", System.Net.HttpUtility.UrlEncode(VM.LoadContext.Identity.ToString()), photo.PhotoId, VM.GetType().FullName));

            btn.NavigateUri = new Uri(url, UriKind.Relative);
        }
コード例 #3
0
ファイル: PhotoRepository.cs プロジェクト: notiedowns/PhotoB
        public void Updatephoto(PhotoVm photoVm)
        {
            using (var model = new PhotoBEntities())
            {
                var photo = model.Photos.FirstOrDefault(x => x.Id == photoVm.Id);
                if (photo != null)
                {
                    photo.Name          = photoVm.Name;
                    photo.Number        = photoVm.Number;
                    photo.CategoryId    = photoVm.CategoryId.Value;
                    photo.Price         = photoVm.Price.Value;
                    photo.ImagePath     = photoVm.ImagePath;
                    photo.Author        = photoVm.Author;
                    photo.LastChangedBy = "System";
                    photo.LastChanged   = DateTime.Now;
                }

                model.SaveChanges();
            }
        }
コード例 #4
0
ファイル: PhotoRepository.cs プロジェクト: notiedowns/PhotoB
        public void EditPhoto(PhotoVm photoVm)
        {
            using (var model = new PhotoBEntities())
            {
                var photo = new Photo
                {
                    Name          = photoVm.Name,
                    Number        = photoVm.Number,
                    CategoryId    = photoVm.CategoryId.Value,
                    Price         = photoVm.Price.Value,
                    ImagePath     = photoVm.ImagePath,
                    DateListed    = DateTime.Now,
                    Author        = photoVm.Author,
                    LastChangedBy = "System",
                    LastChanged   = DateTime.Now
                };

                model.Photos.Add(photo);

                model.SaveChanges();
            }
        }