/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private AttachmentVM GetUpdatedModel() { AttachmentVM model = new AttachmentVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (sessionManager.CurrentAttachment != null) { model.AttachmentItem = sessionManager.CurrentAttachment; } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (sessionManager.CurrentAttachment != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.AttachmentItem); //*************************************************************************************************************************** } SetAccessContext(model); return(model); }
private void RepopulateListsFromCacheSession(AttachmentVM model) { // Populate cached lists if they are empty. Will invoke service call AttachmentLookupListsCacheObject CachedLists = cacheManager.AttachmentListCache; // Retrieve any cached lists to model model.IncidentList = CachedLists.IncidentList; }
public ActionResult Edit() { // Retrieve ID from session string code = sessionManager.AttachmentCode; AttachmentVM model = new AttachmentVM(); // Not from staff or error if (String.IsNullOrEmpty(code)) { //If session has lists then use them RepopulateListsFromCacheSession(model); //Assume we are in create mode as no code passed model.AttachmentItem = new AttachmentModel(); } //if we have been passed a code then assume we are in edit situation and we need to retrieve from the database. else { // Create service instance IUcbService sc = UcbService; try { // Call service to get Attachment item and any associated lookups AttachmentVMDC returnedObject = sc.GetAttachment(CurrentUser, CurrentUser, appID, "", code); // Close service communication ((ICommunicationObject)sc).Close(); //Get view model from service model = ConvertAttachmentDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the service version sessionManager.AttachmentServiceVersion = model.AttachmentItem; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc); model.Message = message; return(View(model)); } } //Adds current retrieved Attachment to session sessionManager.CurrentAttachment = model.AttachmentItem; SetAccessContext(model); return(View(model)); }
private void SetFlagsFalse(AttachmentVM model) { model.IsDeleteConfirmed = "False"; model.IsExitConfirmed = "False"; model.IsNewConfirmed = "False"; //Stop the binder resetting the posted values ModelState.Remove("IsDeleteConfirmed"); ModelState.Remove("IsExitConfirmed"); ModelState.Remove("IsNewConfirmed"); }
private void DetermineIsDirty(AttachmentVM model) { //Compare the Attachment to the original session if (model.AttachmentItem.PublicInstancePropertiesEqual(sessionManager.AttachmentServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private AttachmentVM ConvertAttachmentDC(AttachmentVMDC returnedObject) { AttachmentVM model = new AttachmentVM(); // Map Attachment Item model.AttachmentItem = Mapper.Map <AttachmentDC, AttachmentModel>(returnedObject.AttachmentItem); // Map lookup data lists model.IncidentList = Mapper.Map <IEnumerable <IncidentDC>, List <IncidentModel> >(returnedObject.IncidentList); return(model); }
private void SetAccessContext(AttachmentVM model) { //Decide on access context if (null == model.AttachmentItem || model.AttachmentItem.Code == Guid.Empty) { // Create context model.AccessContext = AttachmentAccessContext.Create; } else { // Edit context model.AccessContext = AttachmentAccessContext.Edit; } }
public ActionResult StoreAttachmentInCache(string guid, string content, string filename) { if (this.UserData == null || (this.UserData != null && this.UserData.LevelId != 2)) { return(RedirectToAction(Url.Action("Login", "User"))); } AttachmentVM att = new AttachmentVM() { Content = Convert.FromBase64String(content.Split(',')[1]), Filename = filename, Guid = guid }; HttpContext.Cache.Add(att.Guid, att, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); return(Json("OK", JsonRequestBehavior.AllowGet)); }
public async Task SendMessage(string message, string chatId, string cacheId) { //var chatId = _connections[Context.ConnectionId]; var userData = await GetUserData(); if (userData != null) { ChatItemVM chatItem = null; if (cacheId != null) { AttachmentVM att = HttpContext.Current.Cache[cacheId] as AttachmentVM; chatItem = new ChatItemVM() { ChatId = int.Parse(chatId), OnDate = DateTime.Now, SiteUserId = userData.UserId, FileName = System.IO.Path.GetFileName(att.Filename), Said = message, Attachment = att.Content }; } else { chatItem = new ChatItemVM() { ChatId = int.Parse(chatId), OnDate = DateTime.Now, SiteUserId = userData.UserId, Said = message, Attachment = null, FileName = null }; await _cs.CreateChatItem(chatItem); } Int32 id = await _cs.CreateChatItem(chatItem); chatItem.ChatItemId = id; Clients.Group($"group-{chatId}").SendMessage(userData.UserId, userData.Username, DateTime.Now.ToString(), chatItem); } }
public void SetGroup(FrameGroup group) { if (group == null) { return; } // Attaching capture AttachmentVM capture = new AttachmentVM(new FileAttachment() { FileType = FileAttachment.Type.CAPTURE }); if (!String.IsNullOrEmpty(group.Name) && File.Exists(group.Name) && false) { capture.Attachment.Name = Path.GetFileName(group.Name); capture.Attachment.Data = new FileStream(group.Name, FileMode.Open); } else { capture.Attachment.Name = "Capture.opt"; capture.Attachment.Data = new MemoryStream(); Task.Run(() => { Application.Current.Dispatcher.Invoke(() => { capture.IsUploading = true; capture.Status = "Saving capture..."; }); group.Save(Capture.Create(capture.Attachment.Data)); Application.Current.Dispatcher.Invoke(() => { capture.IsUploading = false; capture.Status = String.Empty; capture.Size = capture.Attachment.Data.Length; }); }); } Attachments.Add(capture); // Attaching all the extracted attachments foreach (FileAttachment att in group.Summary.Attachments) { Attachments.Add(new AttachmentVM(att)); } }
private void ResolveFieldCodesToFieldNamesUsingLists(AttachmentVM model) { //TODO: }