示例#1
0
        public FollowUpBase AddNewFollowUp(FollowUpAdd newItem)
        {
            //Addeditem variable
            var addedItem = new FollowUp();

            //Insert value
            addedItem = Mapper.Map <FollowUp>(newItem);

            //Insert suggestion object
            addedItem.Suggestion = ds.Suggestions.Find(newItem.SuggestionId);
            addedItem.Suggestion.FollowUps.Add(addedItem);

            //Handle the uploaded image
            //Add attachment only if there is image
            if (newItem.AttachmentUpload != null)
            {
                byte[] attachmentBytes = new byte[newItem.AttachmentUpload.ContentLength];
                newItem.AttachmentUpload.InputStream.Read(attachmentBytes, 0, newItem.AttachmentUpload.ContentLength);

                //ojbect property
                addedItem.Attachment  = attachmentBytes;
                addedItem.ContentType = newItem.AttachmentUpload.ContentType;
            }

            ds.FollowUps.Add(addedItem);

            ds.SaveChanges();

            return(Mapper.Map <FollowUpBase>(addedItem));
        }
 public ActionResult Create(FollowUpAdd newItem)
 {
     if (!ModelState.IsValid)
     {
         return(HttpNotFound());
     }
     else
     {
         var addedItem = m.AddNewFollowUp(newItem);
         if (addedItem == null)
         {
             return(HttpNotFound());
         }
         else
         {
             return(RedirectToAction("index"));
         }
     }
 }