示例#1
0
        public ActionResult Create(Store item)
        {
            item.Taxpayer = TaxpayerIssuer.TryFind(item.TaxpayerId);
            item.Location = SatPostalCode.TryFind(item.LocationId);

            if (!ModelState.IsValid)
            {
                return(PartialView("_Create", item));
            }

            using (var scope = new TransactionScope()) {
                item.ReceiptMessage = string.Format("{0}", item.ReceiptMessage).Trim();
                item.Address.Create();
                item.CreateAndFlush();
            }

            return(PartialView("_Refresh"));
        }
示例#2
0
        public ActionResult Edit(Store item)
        {
            item.Taxpayer = TaxpayerIssuer.TryFind(item.TaxpayerId);
            item.Location = SatPostalCode.TryFind(item.LocationId);

            if (!ModelState.IsValid || item.Taxpayer == null)
            {
                return(PartialView("_Edit", item));
            }

            var entity  = Store.Find(item.Id);
            var address = entity.Address;

            entity.Code           = item.Code;
            entity.Name           = item.Name;
            entity.Taxpayer       = item.Taxpayer;
            entity.Logo           = item.Logo;
            entity.Location       = item.Location;
            entity.ReceiptMessage = item.ReceiptMessage?.Trim();

            using (var scope = new TransactionScope()) {
                if (!address.Equals(item.Address))
                {
                    entity.Address = item.Address;
                    entity.Address.Create();
                }

                entity.UpdateAndFlush();
            }

            if (!address.Equals(item.Address))
            {
                try {
                    using (var scope = new TransactionScope()) {
                        address.DeleteAndFlush();
                    }
                } catch (Exception ex) {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }

            return(PartialView("_Refresh"));
        }