Beispiel #1
0
        public ActionResult Detail(int id, string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            ViewBag.tags      = TagHelper.GetTags(id, "NonProfitOrg");
            NonProfitOrg model;

            if (id == 0)
            {
                model = new NonProfitOrg();
                model.IdentificationNumber = EntityHelper.Create16DigitString();
            }
            else
            {
                model = new Entities().NonProfitOrg.Single(e => e.Id == id);
            }
            if (model.Deleted)
            {
                ViewBag.CanEdit = false;
            }
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Detail(int id, NonProfitOrg model, string returnUrl, FormCollection m)
        {
            ViewBag.ReturnUrl = returnUrl;
            ViewBag.tags      = m["tags"];

            using (var scope = new TransactionScope(
                       TransactionScopeOption.RequiresNew,
                       new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.ReadCommitted
            }))
            {
                Entities cx = new Entities();

                //update NonProfitOrg
                NonProfitOrg p = null;
                try
                {
                    if (model.Id == 0)
                    {
                        p = model;
                        cx.NonProfitOrg.Add(p);
                        p.Updated   = DateTime.UtcNow;
                        p.UpdatedBy = NonProfitCRM.Components.SystemHelper.GetUserName;
                        Logger.Log(NonProfitCRM.Components.SystemHelper.GetUserName, "Create NonProfitOrg " + model.Name + " / " + p.IdentificationNumber, null, model, "NonProfitOrg", p.Id);
                        cx.SaveChanges();
                    }
                    else
                    {
                        p = cx.NonProfitOrg.Single(e => e.Id == id);
                        string _oldObject = Logger.Serialize(p);
                        p.Address              = model.Address;
                        p.Capacity             = model.Capacity;
                        p.City                 = model.City;
                        p.Contact1Email        = model.Contact1Email;
                        p.Contact1Name         = model.Contact1Name;
                        p.Contact1Note         = model.Contact1Note;
                        p.Contact1Phone        = model.Contact1Phone;
                        p.Contact2Email        = model.Contact2Email;
                        p.Contact2Name         = model.Contact2Name;
                        p.Contact2Note         = model.Contact2Note;
                        p.Contact2Phone        = model.Contact2Phone;
                        p.CountryId            = model.CountryId;
                        p.IdentificationNumber = model.IdentificationNumber;
                        p.Name                 = model.Name;
                        p.Note                 = model.Note;
                        p.RegionId             = model.RegionId;
                        p.TypeId               = model.TypeId;
                        p.Www       = model.Www;
                        p.Updated   = DateTime.UtcNow;
                        p.UpdatedBy = NonProfitCRM.Components.SystemHelper.GetUserName;
                        cx.SaveChanges();
                        Logger.Log(NonProfitCRM.Components.SystemHelper.GetUserName, "Modify NonProfitOrg " + model.Name + " / " + p.IdentificationNumber,
                                   _oldObject, Logger.Serialize(p), "NonProfitOrg", p.Id);
                    }
                    TagHelper.SetTags(p.Id, "NonProfitOrg", m["tags"], cx);
                }
                catch (DbUpdateException e)
                {
                    var sqlException = e.GetBaseException() as SqlException;
                    if (sqlException != null)
                    {
                        if (sqlException.Errors.Count > 0)
                        {
                            switch (sqlException.Errors[0].Number)
                            {
                            case 2601:     // Foreign Key violation
                                ModelState.AddModelError("ICOIssue", "Neziskovka se stejným IČ již existuje!");
                                return(View(model));

                            default:
                                throw;
                            }
                        }
                    }
                    else
                    {
                        throw;
                    }
                }

                scope.Complete();
                StatisticsHelper.InvalidateCacheCRM();
            }

            // redirect
            if (returnUrl != null && returnUrl.Length > 0)
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToAction("List", "NonProfitOrg"));
            }
        }