Esempio n. 1
0
        public Entity Create(long userId, Entity toAdd, Address address = null)
        {
            using (var tran = new TransactionScope())
            {
                var toRet = _repository.Create(toAdd);

                if (address != null)
                {
                    address.Entity = toRet;
                    //Create related address
                    var blAddress = new BlAddress();
                    blAddress.Create(userId, address);
                }

                BlLog.Log(userId, Module, "Create entity", "EntityCreated", new object[] { toAdd.Pin });
                tran.Complete();
                return(toRet);
            }
        }
Esempio n. 2
0
        public static Address GetDefaultAddress(long userId, long pin, bool withFullAddress = false)
        {
            var predicate = PredicateBuilder.True <Address>();

            predicate = predicate.And(m => m.Entity.Pin == pin);
            predicate = predicate.And(m => m.Sequence == 1);

            var blAddress = new BlAddress();
            var toRet     = blAddress.LoadSearch(userId, predicate, 1).SingleOrDefault() ?? new Address()
            {
                Country  = "0",
                Province = "0",
                Caza     = "0",
                Region   = "",
                Street   = "",
                Building = "",
                Floor    = "0",
                Phone1   = "",
                Phone2   = "",
                Phone3   = "",
                Fax      = ""
            };

            if (withFullAddress)
            {
                //Set the full address
                toRet.FullAddress = string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}-{8}-{9}-{10}",
                                                  BlCode.LoadSingle(userId, "Country", toRet.Country ?? "0").Value1,
                                                  BlCode.LoadSingle(userId, "Province", toRet.Province ?? "0").Value1,
                                                  BlCode.LoadSingle(userId, "Caza", toRet.Caza ?? "0").Value1,
                                                  toRet.Region,
                                                  toRet.Street,
                                                  toRet.Building,
                                                  BlCode.LoadSingle(userId, "Floor", toRet.Floor ?? "0").Value1,
                                                  toRet.Phone1,
                                                  toRet.Phone2,
                                                  toRet.Phone3,
                                                  toRet.Fax);
            }

            return(toRet);
        }
Esempio n. 3
0
        public Entity Edit(long userId, Entity toEdit, Address address = null)
        {
            using (var tran = new TransactionScope())
            {
                var toRet = _repository.Edit(toEdit);

                if (address != null)
                {
                    if (address.Id != 0)
                    {
                        address.Entity = toRet;
                        //Edit related address
                        var blAddress = new BlAddress();
                        blAddress.Edit(userId, address);
                    }
                }

                BlLog.Log(userId, Module, "Edit entity", "EntityModified", new object[] { toEdit.Pin });
                tran.Complete();
                return(toRet);
            }
        }