public async Task <IActionResult> PutUsersAddress(int id, UsersAddress usersAddress)
        {
            if (id != usersAddress.UserAddressId)
            {
                return(BadRequest());
            }

            _context.Entry(usersAddress).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsersAddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <UsersAddress> > PostUsersAddress(UsersAddress usersAddress)
        {
            _context.UsersAddress.Add(usersAddress);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUsersAddress", new { id = usersAddress.UserAddressId }, usersAddress));
        }
Ejemplo n.º 3
0
        public JsonResult <Object> AddUserAddress(string UserID, string AddressTitle, string Address)
        {
            bool result = false;

            try
            {
                UsersAddress userAddress = new UsersAddress();
                userAddress.AspNetUserID = UserID;
                userAddress.AddressTitle = AddressTitle;
                userAddress.Address      = Address;
                userAddress.DeliveringTo = true;

                using (var db = new BookPoolEntities())
                {
                    db.UsersAddresses.Where(x => x.AspNetUserID == UserID).Select(x => x).ForEach(x => x.DeliveringTo = false);
                    db.UsersAddresses.Add(userAddress);
                    db.SaveChanges();
                }

                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(Json((object)new { result }));
        }
Ejemplo n.º 4
0
        public HttpResponseMessage AddAddress(Address objAddress)
        {
            try
            {
                UsersAddress objUsersAddress = new UsersAddress();
                string       mobileNumber    = objAddress.retailer_mobile;
                //get mobileNumber from user table
                var number = (from user in dbContext.UserInfo where user.MobileNumber == mobileNumber select user).FirstOrDefault();
                if (number != null)
                {
                    objUsersAddress.retailer_id           = objAddress.retailer_id;
                    objUsersAddress.MobileNumberForOnline = objAddress.retailer_mobile;
                    objUsersAddress.reciver_name          = objAddress.reciver_name;
                    objUsersAddress.ship_address          = objAddress.ship_address;
                    objUsersAddress.city        = objAddress.city;
                    objUsersAddress.pincode     = objAddress.pincode;
                    objUsersAddress.ship_mobile = objAddress.ship_mobile;
                    objUsersAddress.email_id    = objAddress.email_id;
                    objUsersAddress.Pan_number  = objAddress.PanNumber;
                    objUsersAddress.tr_date     = !string.IsNullOrEmpty(objAddress.tr_date) ? Convert.ToDateTime(objAddress.tr_date) : (DateTime?)null;


                    dbContext.UsersAddress.Add(objUsersAddress);
                    var i = dbContext.SaveChanges();
                    if (i != 0)
                    {
                        objResponse.Message = "Added successfully";
                        return(Request.CreateResponse(HttpStatusCode.OK, objResponse));
                    }
                    else
                    {
                        objResponse.Message = "Failed";
                        return(Request.CreateResponse(HttpStatusCode.OK, objResponse));
                    }
                }
                else
                {
                    objResponse.Message = "Mobile number not exists.";

                    return(Request.CreateResponse(HttpStatusCode.OK, objResponse));
                }
            }
            catch (Exception ex)
            {
                Log.Info(Convert.ToString(ex.InnerException));
                Log.Info(ex.Message);
                objCommonClasses.InsertExceptionDetails(ex, "UserController", "AddAddress");
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex.Message));
            }
        }
Ejemplo n.º 5
0
        //2.1.2【延迟加载】- 针对于 外键实体 的延迟(按需加载)!
        //                  本质原因之二:对于外键属性而言,EF会在用到这个外键属性的时候才去查询 对应的 表。
        private void QueryDelay_02()
        {
            IQueryable <UsersAddress> addrs = db.UsersAddresses.Where(a => a.udUId == 1);//真实返回的 DbQuery 对象,以接口方式返回
            //a.此时只查询了 地址表
            UsersAddress addr01 = addrs.FirstOrDefault();

            //b.当访问 地址对象 里的 外键实体时,EF会查询 地址对应 的用户表;查询到之后,将数据 装入 这个外键实体
            Console.WriteLine(addr01.User.uName);

            //c.【延迟加载】按需加载 的缺点:每次调用外键实体时,都会去查询数据库(EF有小优化:相同的外键实体只查一次)
            IQueryable <UsersAddress> addrs2 = db.UsersAddresses;

            foreach (UsersAddress add in addrs2)
            {
                Console.WriteLine(add.udAddress + ":userName=" + add.User.uName);
            }
        }
Ejemplo n.º 6
0
        public JsonResult <Object> DeliveringToUserAddress(string UserID, int AddressID)
        {
            bool result = false;

            try
            {
                using (var db = new BookPoolEntities())
                {
                    db.UsersAddresses.Where(x => x.AspNetUserID == UserID).Select(x => x).ForEach(x => x.DeliveringTo = false);
                    UsersAddress usersAddress = db.UsersAddresses.First(x => x.ID == AddressID);
                    usersAddress.DeliveringTo = true;
                    db.SaveChanges();
                }

                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(Json((object)new { result }));
        }
Ejemplo n.º 7
0
        public async Task <HttpResponseMessage> DeleteDevices(RequestLocationDataVM model)
        {
            Notification        objNotifications = new Notification();
            DeviceAssociateSite deviceStatus     = null;

            using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository())
            {
                Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId);

                foreach (var item in model.MacAddresses)
                {
                    // When Device is coming to delete in OmniEngiene
                    int deviceId = _OmniDeviceMappingRepository.GetDeviceId(item);
                    deviceStatus = objRtlsConfigurationRepository.DeviceAssociateSiteStatus(deviceId);
                    if (deviceStatus.status == DeviceStatus.DeRegistered)
                    {
                        OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness();
                        RequestOmniModel   objRequestOmniModel   = new RequestOmniModel();
                        objRequestOmniModel.MacAddress = item;
                        var returnStatus = await objOmniEngineBusiness.DeleteDevices(objRequestOmniModel);

                        if (returnStatus == true)
                        {
                            try
                            {
                                //Delete Device ralated data
                                DeviceAssociateSite _DeviceAssociateSite = db.DeviceAssociateSite.FirstOrDefault(k => k.DeviceId == deviceId);
                                Device            _Device            = db.Device.FirstOrDefault(p => p.DeviceId == deviceId);
                                NetWorkOfSite     _NetworkOfSite     = db.NetWorkOfSite.Where(p => p.SiteId == model.SiteId).Where(q => q.LocServiceTypeId != 0).FirstOrDefault();
                                OmniDeviceMapping _OmniDeviceMapping = db.OmniDeviceMapping.FirstOrDefault(k => k.DeviceId == deviceId);

                                //If User registered from CaptivePortal
                                if (_DeviceAssociateSite.IsRegisterInCaptivePortal == true)
                                {
                                    WifiUserLoginCredential _WifiUserLoginCredential = db.WifiUserLoginCredential.Where(p => p.Device.DeviceId == deviceId).Where(q => q.NetWorkOfSiteId == _NetworkOfSite.NetWorkOfSiteId).FirstOrDefault();
                                    WifiUser     _WifiUser     = db.WifiUser.Where(p => p.UserId == _WifiUserLoginCredential.WifiUserId).FirstOrDefault();
                                    UsersAddress _UsersAddress = db.UsersAddress.Where(p => p.UserId == _WifiUser.UserId).FirstOrDefault();
                                    db.UsersAddress.Remove(_UsersAddress);
                                    db.WifiUser.Remove(_WifiUser);
                                    db.WifiUserLoginCredential.Remove(_WifiUserLoginCredential);
                                }


                                db.DeviceAssociateSite.Remove(_DeviceAssociateSite);
                                db.OmniDeviceMapping.Remove(_OmniDeviceMapping);
                                db.Device.Remove(_Device);
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                log.Error(ex.Message);
                            }
                        }
                    }
                }
            }

            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }