public ActionResult FileDelete(PictureFileRecord rec) { ChangeResult result = new ChangeResult(); string status = PictureFileRecord.GetStatusString(rec.Status); bool display = rec.Status == PictureFileRecord.StatusType.Archived || rec.Status == PictureFileRecord.StatusType.ForSale; bool archive = rec.Status == PictureFileRecord.StatusType.Archived; try { //List<PictureFileRecord> fileRecords = // service.DeletePictureFile(rec.FileName, archive, display, service.FullyMappedPictureFolder).ToList(); result = service.DeletePictureFile(rec.FileName, archive, display, service.FullyMappedPictureFolder); } catch (Exception anEx) { // log but don't halt execution - the javascript function has fired, possibly at an inappropriate time. // This is most likely because of not-fully-understood interaction between the paging control and onclick // event in webgrid Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(anEx)); } // RedirectToAction works by sending an http 302 response to browser which causes the // browser to make a GET request to the action - this is precisely what we want return RedirectToAction("Index", new { status = PictureFileRecord.GetStatusString(rec.Status), initial = false }); //var jsondata = new //{ // data = result, // view = RenderHelper.PartialView(this, (display) ? "_PictureList" : "_NonOrderablePictureList", load(status)) //}; }
public ExtendedJsonResult(ChangeResult data) { base.Data = data; Success = data.Success; Message = data.Message; StatusCode = data.StatusCode; }
/// <summary> /// Promotes the item in its list /// This action reduces the order number of the item by one if the order value is greater than zero. /// The order value of the preceding item is increased by one. /// </summary> /// <param name="rec"></param> /// <returns></returns> public ActionResult FilePromote(PictureFileRecord rec) { ChangeResult result = new ChangeResult(); try { result = service.AdvanceInList(rec); } catch (Exception anEx) { // log but don't halt execution Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(anEx)); } // RedirectToAction works by sending an http 302 response to browser which causes the // browser to make a GET request to the action - this is precisely what we want return RedirectToAction("Index", new { status = PictureFileRecord.GetStatusString(rec.Status), initial = false }); }
/// <summary> /// Exchange the order values of posting1 and posting2 /// </summary> /// <param name="posting1"></param> /// <param name="posting2"></param> /// <param name="archived"></param> /// <returns></returns> ChangeResult IPostingRepository.ExchangeOrders(ItemPosting posting1, ItemPosting posting2, bool archived) { int order1 = posting1.Order; int order2 = posting2.Order; ChangeResult result = new ChangeResult(); string commandText = "Update [dbo].[ArtPostingItems] " + "SET [Order] = @neworder " + "WHERE Id = @id"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (SqlTransaction transaction = connection.BeginTransaction()) { int updated = 0; try { SqlDataAdapter adapter = new SqlDataAdapter(); // update #1: set 1 to 2 adapter.UpdateCommand = new SqlCommand(commandText, connection, transaction); SqlParameter newOrderParam = new SqlParameter("@neworder", SqlDbType.Int); newOrderParam.Value = order2; SqlParameter idParam = new SqlParameter("@id", SqlDbType.Int); idParam.Value = posting1.Id; adapter.UpdateCommand.Parameters.Add(newOrderParam); adapter.UpdateCommand.Parameters.Add(idParam); updated = adapter.UpdateCommand.ExecuteNonQuery(); // update #2: set 2 to 1 if (updated > 0) { updated = 0; newOrderParam.Value = order1; idParam.Value = posting2.Id; updated = adapter.UpdateCommand.ExecuteNonQuery(); } // commit if (updated > 0) { transaction.Commit(); } else { throw new Exception("There was a problem changing the orders of " + posting1.FileName + " and " + posting2.FileName); } } catch (Exception ex) { transaction.Rollback(); return new ChangeResult(false, ex.Message, HTTP_INTERNAL_SERVER_ERROR); } } result = new ChangeResult(true, "Promoted: " + posting1.FileName.Normalise(), HTTP_SUCCESS); return result; } }
public ChangeResult MovePicture(string filepath, bool archivedestination, bool displaydestination) { // filepaths / names brought in from ajax call will have %20 spaces and will not have JS escaped single quotes string filename = Utility.GetFilenameFromFilepath(filepath).Normalise(); // default constructor gives failed results ChangeResult removeResult = new ChangeResult(); ChangeResult insertResult = new ChangeResult(); // initialising variables PictureFileRecord pfr = new PictureFileRecord(filepath); PictureFileRecord.StatusType source; List<ItemPostingViewModel> postingVMs = new List<ItemPostingViewModel>(); // getting current database contents postingVMs.AddRange(ArchivePostings().ToList()); postingVMs.AddRange(ShopPostings().ToList()); // getting full info on item to move ItemPostingViewModel moveItem = postingVMs.FirstOrDefault(x => x.ItemPosting.FileName.ToUpper().Normalise() == filename.ToUpper()); ItemPosting posting = new ItemPosting(); // determine current location of move item if (moveItem == null) { source = PictureFileRecord.StatusType.NotDisplayed; } else { posting = moveItem.ItemPosting; if (posting.Archive_Flag == true) { source = PictureFileRecord.StatusType.Archived; } else { source = PictureFileRecord.StatusType.ForSale; } } if (displaydestination) { // (1) the move item's being moved to the list it's already in if (archivedestination && source == PictureFileRecord.StatusType.Archived || !archivedestination && source == PictureFileRecord.StatusType.ForSale) { return new ChangeResult( false, filename + " is already included in the " + ((archivedestination) ? "Archive" : "Home") + " page", 400); } else { // (2) the moveItem's being moved from one list to another if (archivedestination && source == PictureFileRecord.StatusType.ForSale || !archivedestination && source == PictureFileRecord.StatusType.Archived) { removeResult = RemoveFromDisplay(posting); insertResult = InsertPosting(pfr, archivedestination); return insertResult; } else { // (3) the moveItem's being moved onto a list from not_displayed insertResult = InsertPosting(pfr, archivedestination); return insertResult; } } } // (4) the moveItem's being removed from all lists else { if (source == PictureFileRecord.StatusType.NotDisplayed) { return new ChangeResult( false, filename + " is not currently displayed, and therefore is not in the database. Therefore it cannot be removed from the database", 500); } else { removeResult = RemoveFromDisplay(posting); return removeResult; } } }
/// <summary> /// Promotes the item in its list /// This action reduces the order number of the item by one if the order value is greater than zero. /// The order value of the preceding item is increased by one. /// </summary> /// <param name="rec"></param> /// <returns></returns> ChangeResult IPostingService.AdvanceInList(PictureFileRecord rec) { ChangeResult result = new ChangeResult(); int order; bool archive = rec.Status == PictureFileRecord.StatusType.Archived; string encodedFilename = HttpUtility.UrlPathEncode(rec.FileName); ItemPosting subjectItem = repository.GetPosting(x => x.FileName.ToUpper() == encodedFilename.ToUpper(), archive); try { order = Convert.ToInt32(subjectItem.Order); if (order > 0) { // get previously ordered item ItemPosting precedingItem = repository.GetPosting(pre => pre.Order == subjectItem.Order - 1, archive); result = repository.ExchangeOrders(subjectItem, precedingItem, archive); } else { result = new ChangeResult(false, "Cannot promote item which is at the top of the list", 400); } } catch (Exception anEx) { // log but don't halt execution - the javascript function has fired, most likely because // of difficult-to-understand interaction between the paging control and onclick event in webgrid Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(anEx)); } return result; }
public ChangeResult DeletePictureFile(string filename, bool archive, bool display, string folder) { ChangeResult result = new ChangeResult(); if (display) { // file is in database ItemPosting posting = repository.GetPosting(x => x.FileName.Normalise().ToUpper() == filename.Normalise().ToUpper(), archive); if (posting == null) { // did not find filename - something's wrong, so don't delete file result = new ChangeResult(false, "Error deleting " + filename + " from database", HTTP_INTERNAL_SERVER_ERROR); Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(new Exception(result.Message))); return result; } // remove from database result = repository.Delete(posting); } //return PictureFileRecordList(folder); // delete file File.Delete(Path.Combine(FullyMappedPictureFolder, filename)); return new ChangeResult(true, "Deleted " + filename, HTTP_SUCCESS); ; }