예제 #1
0
        public static ReturnJasonConstruct <DTO.Address> Update(DTO.Address dto)
        {
            ReturnJasonConstruct <DTO.Address> obj = new ReturnJasonConstruct <DTO.Address>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                if (dto.defaultAddress == true)//Need set other address to undefault
                {
                    StaticSetAddressUndefault(ref db, dto.accountId);
                }

                var model = db.Addresses.Single(p => p.id == dto.id);
                model.Address1       = dto.Address1;
                model.tel            = dto.tel;
                model.name           = dto.name;
                model.defaultAddress = dto.defaultAddress;
                db.SaveChanges();

                obj.SetDTOObject(model.ToDTO());
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
            return(obj);
        }
예제 #2
0
        public static ReturnJasonConstruct <DTO.Address> Create(DTO.Address dto)
        {
            ReturnJasonConstruct <DTO.Address> obj = new ReturnJasonConstruct <DTO.Address>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                if (db.Addresses.Count(p => p.accountId == dto.accountId) == maxAddressCount)
                {
                    obj.SetWarningInformation("您的地址数不能超过6个,请删除其他地址来添加地址信息");
                    return(obj);
                }
                if (dto.defaultAddress == true)//Need set other address to undefault
                {
                    StaticSetAddressUndefault(ref db, dto.accountId);
                }

                Models.Address model = dto.ToModel();
                model.id = Guid.NewGuid();
                db.Addresses.Add(model);
                db.SaveChanges();
                obj.SetDTOObject(model.ToDTO());
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
            return(obj);
        }
예제 #3
0
 public ReturnJasonConstruct <DTO.Address> Put([FromBody] DTO.Address address)
 {
     return(Services.Address.Update(address));
 }