Beispiel #1
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            //Get Item From Database
            ContactType contactType = new ContactType();

            contactType = contactTypeRepository.GetContactType(id);

            //Check Exists
            if (contactType == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToReferenceInfo())
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }


            //Delete Item
            try
            {
                contactType.VersionNumber = Int32.Parse(collection["VersionNumber"]);
                contactTypeRepository.Delete(contactType);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/ContactType.mvc/Delete/" + id.ToString();
                    return(View("VersionError"));
                }
                if (ex.Message == "SQLDeleteErrorError")
                {
                    ViewData["ReturnURL"] = "/ContactType.mvc/Delete/" + id.ToString();
                    return(View("DeleteError"));
                }

                //Generic Error
                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            //Return
            return(RedirectToAction("List"));
        }
 public void ContactType05DeleteTest()
 {
     repository.Delete(2);
     Assert.IsTrue(repository.Save());
 }