public ActionResult Create(RecieverResponse recieverresponse)
 {
     if (ModelState.IsValid) {
         recieverresponseRepository.InsertOrUpdate(recieverresponse);
         recieverresponseRepository.Save();
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }
        public ActionResult Create(CaseItem caseitem, HttpPostedFileBase image, HttpPostedFileBase document)
        {
            if (Session["uid"] != null)
            {
                long userId = Convert.ToInt64(Session["uid"].ToString());
                caseitem.Owner = userId;

                RecieverResponse resp = new RecieverResponse();
                resp.ResponseCode = GenerateResponseCode(caseitem);
                recieverresponseRepository.InsertOrUpdate(resp);
                recieverresponseRepository.Save();

                caseitem.caseMode = 0;
                caseitem.Created = DateTime.Now;
                caseitem.LastEdited = DateTime.Now;
                caseitem.ResponseID = resp.ResponseID;
                caseitem.Archived = false;

                if (ModelState.IsValid)
                {
                    caseitemRepository.InsertOrUpdate(caseitem);
                    caseitemRepository.Save();

                    //validering och sparning av bild
                    if (image != null)
                    {
                        switch (image.ContentType)
                        {
                            //tillåtna filtyper:
                            case "image/jpeg":
                            case "image/png":
                            case "image/gif":
                                CaseImage img = new CaseImage();
                                img.CaseID = caseitem.ID;

                                //Genererar strängar som ska läggas till på bildens namn för att göra namnet unikt:
                                string imgGUID = Guid.NewGuid().ToString();

                                //sparar originalbilden i /Content/uploadedImages/:
                                string imgLocation = "~/Content/uploadedImages/" + imgGUID + "_" + image.FileName;
                                img.ImageUrl = imgLocation;
                                image.SaveAs(Server.MapPath(imgLocation));

                                //Skapar en ny resizead bild som ska användas som thumbnail
                                Image srcImage = Image.FromStream(image.InputStream);
                                Image thumbnail = new Bitmap(srcImage, 130, 130);
                                srcImage.Dispose();

                                //Sparar thumbnailen i /Content/uploadedThumbnails/:
                                string thumbnailLocation = "~/Content/uploadedThumbnails/" + imgGUID + "_" + image.FileName;
                                caseitem.ImageThumbnail = thumbnailLocation;
                                thumbnail.Save(Server.MapPath(thumbnailLocation));
                                thumbnail.Dispose();
                                //image.InputStream.Read(img.ImageBytes, 0, image.ContentLength);

                                caseimageRepository.InsertOrUpdate(img);
                                caseimageRepository.Save();

                                break;
                            default: //Otillåten filtyp
                                caseitem.ImageThumbnail = null;
                                /* Lägg till validerings-errormeddelande i vy:
                                 * ModelState.AddModelError("key", "message");
                                 * i view: @Html.ValidationSummary(false)
                                 */
                                break;
                        }

                    }
                    else
                    {
                        caseitem.ImageThumbnail = null;
                    }
                    //s**t på validering och sparning bild

                    //dokumentuppladdning:
                    if (document != null)
                    {
                        caseitem.documentMimeType = document.ContentType;
                        caseitem.documentName = document.FileName;
                        string location =   "~/Content/uploadedDocuments/" + document.FileName;
                        caseitem.documentUrl = location;
                        document.SaveAs(Server.MapPath(location));
                    }

                    resp.ResponseCode = GenerateResponseCode(caseitem);
                    recieverresponseRepository.InsertOrUpdate(resp);
                    recieverresponseRepository.Save();

                    var createVoting = Request["create_voting"];

                    //have the user requested a voting on this case?
                    if (createVoting=="true" && Request["voting_title"] != null)
                    {
                        CaseVoting casevoting = new CaseVoting();
                        casevoting.CaseID = caseitem.ID;
                        casevoting.Title = Request["voting_title"];
                        casevoting.StartDate = DateTime.Now;
                        casevoting.EndDate = DateTime.Now;
                        casevoting.Created = DateTime.Now;
                        caseVotingRepository.InsertOrUpdate(casevoting);
                        caseVotingRepository.Save();
                    }

                }
                else
                {
                    ViewBag.PossibleCategories = casecategoryRepository.All;

                }

                caseitem.caseComment = new List<CaseComment>();
                if (ModelState.IsValid)
                {
                    caseitemRepository.InsertOrUpdate(caseitem);
                    caseitemRepository.Save();
                    return RedirectToAction("Index");
                }
                else
                {
                    return View();
                }
            }
            else
            {
                return RedirectToAction("Index");
            }
        }
        public ActionResult Edit(RecieverResponse recieverresponse)
        {
            int caseId = recieverresponseRepository.GetCaseId(recieverresponse.ResponseID);

            if (ModelState.IsValid && caseId != 0) {
                recieverresponseRepository.InsertOrUpdate(recieverresponse);
                recieverresponseRepository.Save();
                return RedirectToAction("Details", "CaseItems", new { id = caseId }); //Redirecta till det ärende som användaren lämnat respons på
            } else {
                return View();
            }
        }