Exemplo n.º 1
0
        public JsonNetResult  GetFranchises(int?incDisabled)
        {
            List <Franchise> _data = new List <Franchise>();

            StringBuilder sql = new StringBuilder(@"select * from Franchises C 
							    inner join Addresses Ph on C.PhysicalAddressRefId = Ph.ID"                                );

            if (!incDisabled.HasValue || incDisabled == 0)
            {
                sql.Append(" where C.IsActive = 1");
            }

            using (DBManager db = new DBManager())
            {
                _data = db.getConnection().Query <Franchise, Address, Franchise>(sql.ToString(), (fr, phys) => {
                    fr.PhysicalAddress = phys;
                    return(fr);
                }).ToList();
            }

            List <UpdateFranchisesViewModel> _editFranchises = new List <UpdateFranchisesViewModel>();

            foreach (Franchise _item in _data)
            {
                var _vm = new UpdateFranchisesViewModel();
                _vm.PopulateVM(_item);
                _editFranchises.Add(_vm);
            }
            return(new JsonNetResult()
            {
                Data = new { list = _editFranchises }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemplo n.º 2
0
        public ActionResult GetFranchise(Guid?FranchiseId)
        {
            //https://msdn.microsoft.com/en-us/data/jj574232.aspx
            Franchise _franchise = null;
            UpdateFranchisesViewModel _dataItem = null;

            if (FranchiseId == null)
            {
                // create new item
                _dataItem                 = new UpdateFranchisesViewModel();
                _dataItem.Id              = Guid.NewGuid().ToString();
                _dataItem.IsNewItem       = true;
                _dataItem.PhysicalAddress = new UpdateAddressViewModel()
                {
                    Id = Guid.NewGuid().ToString(), AddressType = AddressTypeSetting.Physical
                };
                _dataItem.PhysicalAddressRefId = _dataItem.PhysicalAddress.Id;
            }
            else
            {
                string sql = @"select * from Franchises C 
							    inner join Addresses Ph on C.PhysicalAddressRefId = Ph.ID
								where C.Id = '"                                 + FranchiseId + "'";

                using (DBManager db = new DBManager())
                {
                    _franchise = db.getConnection().Query <Franchise, Address, Franchise>(sql, (clnt, phys) => {
                        clnt.PhysicalAddress = phys;
                        return(clnt);
                    }).SingleOrDefault();
                }
                if (_franchise == null)
                {
                    ModelState.AddModelError(string.Empty, $"Franchise [{FranchiseId.ToString()}] not found.  Please try again.");
                    return(JsonFormResponse());
                }

                _dataItem = new UpdateFranchisesViewModel();
                _dataItem.PopulateVM(_franchise);
                _dataItem.IsNewItem = false;
            }

            return(new JsonNetResult()
            {
                Data = new { item = _dataItem }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }