// POST: odata/CustomerAddress public async Task <IHttpActionResult> Post(customer_address customer_address) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.customer_address.Add(customer_address); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (customer_addressExists(customer_address.customer_address_id)) { return(Conflict()); } else { throw; } } return(Created(customer_address)); }
public IHttpActionResult DeleteCustomerAddress(string addrId) { //Sets the return result from SaveChanges() int deleted = 0; //Instantiate the obj designEntity = new online_tshirt_designingEntities(); //Find an appropriate Customer Address //Execute the query and return the entity object customer_address customerMatches = designEntity.customer_address.FirstOrDefault((c) => c.CustAddrId == addrId); if (customerMatches == null) { return(NotFound()); } //Excute the query and return the Object // customer_address customerMatchedAddrr = matches.Single(); //Delete the record from the Database designEntity.customer_address.Remove(customerMatches); deleted = designEntity.SaveChanges(); if (deleted > 0) { return(Ok(true)); } return(NotFound()); }
public IHttpActionResult SaveCustomerAddress([FromBody] customer_address customerAddrr) { //To generate random numbers for HomeBaneerImgId column DateTime dTime = DateTime.Now; //Set Unique id to CustId & CustAddrId column string id = Convert.ToString(dTime.Millisecond); int updatedRecord = 0; //Insert the details into database i.e(EntityDatabase) var newCustomerAddrr = new customer_address { //Add properties to the class CustAddrId = id, CustShipAddr = customerAddrr.CustShipAddr, CustShipCountry = customerAddrr.CustShipCountry, CustShipState = customerAddrr.CustShipState, CustShipCity = customerAddrr.CustShipCity, CustShipPinCode = customerAddrr.CustShipPinCode }; try { //Finally commit the changes the changes and insert the record //In the database designEntity.customer_address.Add(newCustomerAddrr); updatedRecord = designEntity.SaveChanges(); } catch (Exception error) { System.Diagnostics.Debug.WriteLine("Error in Linq", error); } //IF records get updated successfully //if (updatedRecord > 0) //{ // return Ok(); //} return(Ok()); }
// DELETE: odata/CustomerAddress(5) public async Task <IHttpActionResult> Delete([FromODataUri] int key) { customer_address customer_address = await db.customer_address.FindAsync(key); if (customer_address == null) { return(NotFound()); } db.customer_address.Remove(customer_address); await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
// PUT: odata/CustomerAddress(5) public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <customer_address> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } customer_address customer_address = await db.customer_address.FindAsync(key); if (customer_address == null) { return(NotFound()); } patch.Put(customer_address); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!customer_addressExists(key)) { return(NotFound()); } else { throw; } } return(Updated(customer_address)); }
public static RegisterResponse RegisterCustomer(RegisterRequest register) { auctionEntities = new AuctionSystemEntities(); RegisterResponse registerResponse = new RegisterResponse(); //To retrieve customers based on customer email from customer table in database. customer existingCustomer = auctionEntities.customers.Where(c => c.customer_email == register.CustomerEmail).FirstOrDefault(); //Check if customer exists or not if (existingCustomer != null) { //if customer alreay exist then set fault as customer already exist. registerResponse.Fault = new Error { Code = ErrorCodes.EmailAlreadyExist, Message = "User Email already exist" }; return(registerResponse); } //if customer does not exist create customer customer customer = new customer(); customer.customer_firstname = register.CustomerFirstName; customer.customer_lastname = register.CustomerLastName; customer.customer_email = register.CustomerEmail; customer.customer_password = HashPassword(register.CustomerPassword); customer.customer_phone = register.CustomerPhone; //Add customer to customer table in database and save auctionEntities.customers.Add(customer); auctionEntities.SaveChanges(); customer_address address = new customer_address(); address.Address1 = register.Address1; address.Address2 = register.Address2; address.City = register.City; address.Address_State = register.State; address.Zipcode = register.Zipcode; address.country = register.Country; address.customer_id = customer.id; auctionEntities.customer_address.Add(address); auctionEntities.SaveChanges(); customer_payment payment = new customer_payment(); payment.card_number = register.CardNumber; payment.card_pin = register.CardPin; payment.card_holdername = register.CardHolderName; payment.card_expirydate = register.CardExpiryDate; payment.payment_method_id = register.PaymentMethodId; payment.customer_id = customer.id; payment.address_id = address.id; auctionEntities.customer_payment.Add(payment); auctionEntities.SaveChanges(); registerResponse.CustomerId = customer.id; registerResponse.CustomerEmail = customer.customer_email; registerResponse.CustomerFirstName = customer.customer_firstname; registerResponse.CustomerLastName = customer.customer_lastname; return(registerResponse); }
public IHttpActionResult UpdateCustomerAddress([FromBody] CustomerAddressModel theCustomer) { //Instantiate the object designEntity = new online_tshirt_designingEntities(); int updatedRecord = 0; //Execute the query and return the entity object customer_address customerMatches = designEntity.customer_address.FirstOrDefault((c) => c.CustAddrId == theCustomer.CustAddrId && c.CustId == theCustomer.CustId); if (customerMatches == null) { //Generates random numbers for CustAddrId column DateTime dTime = DateTime.Now; //Sets Unique id to CustId & CustAddrId column string id = Convert.ToString(dTime.Millisecond); //Creates the new customer address model customer_address newCustomerAddress = new customer_address { CustAddrId = id, CustShipAddr = theCustomer.CustShipAddr, CustShipCountry = theCustomer.CustShipCountry, CustShipState = theCustomer.CustShipState, CustShipCity = theCustomer.CustShipCity, CustShipPinCode = theCustomer.CustShipPinCode, CustId = theCustomer.CustId }; try { //Finally commit the changes the changes and insert the record //In the database designEntity.customer_address.Add(newCustomerAddress); updatedRecord = designEntity.SaveChanges(); } catch (Exception error) { System.Diagnostics.Debug.WriteLine("Error in Linq", error); } } //Changes the entity object, if it matches else { customerMatches.CustShipAddr = theCustomer.CustShipAddr; customerMatches.CustShipCountry = theCustomer.CustShipCountry; customerMatches.CustShipState = theCustomer.CustShipState; customerMatches.CustShipCity = theCustomer.CustShipCity; customerMatches.CustShipPinCode = theCustomer.CustShipPinCode; try { //Finally commit the changes the changes and insert the record //In the database updatedRecord = designEntity.SaveChanges(); } catch (Exception error) { System.Diagnostics.Debug.WriteLine("Error in Linq", error); } } //IF records get updated successfully if (updatedRecord > 0) { //Return this customerEntireData var customerEntireData = from cust in designEntity.customers join custAddr in designEntity.customer_address on cust.CustId equals custAddr.CustId where cust.CustId == theCustomer.CustId select new { cust.CustId, cust.CustFirstName, cust.CustLastName, cust.CustMobNo, cust.CustEmailAddr, cust.CustImg, custAddr.CustAddrId, custAddr.CustShipAddr, custAddr.CustShipCountry, custAddr.CustShipCity, custAddr.CustShipState, custAddr.CustShipPinCode }; return(Ok(customerEntireData)); } return(NotFound()); }
private void saveButton_Click(object sender, EventArgs e) { if (strId.Text == "" || strFName.Text == "" || strLName.Text == "" || dateofBirth.Value == DateTime.Now || (!checkMale.Checked && !checkFemale.Checked) || ((phoneNumH.Text == "" || areaCodeH.Text == "") && (phoneNumM.Text == "" || areaCodeM.Text == ""))) { MessageBox.Show("לא מולאו כל שדות החובה"); if (strId.Text == "") { strId.BackColor = Color.Red; // color red if id is null } else { strId.BackColor = Color.White; } if (strFName.Text == "") { strFName.BackColor = Color.Red;// color red if first name is null } else { strFName.BackColor = Color.White; } if (strLName.Text == "") { strLName.BackColor = Color.Red;// color red if last name is null } else { strLName.BackColor = Color.White; } if (dateofBirth.Value == DateTime.Now) { dateofBirth.BackColor = Color.Red; } else { dateofBirth.BackColor = Color.White; } if (!checkMale.Checked && !checkFemale.Checked) { checkMale.BackColor = Color.Red; checkFemale.BackColor = Color.Red; } else { checkMale.BackColor = Color.White; checkFemale.BackColor = Color.White; } } else { var ans = (from cust in dc.Customers where cust.Id == strId.Text select cust).FirstOrDefault(); if (ans != null) { MessageBox.Show("מקבל שירות כבר קיים במערכת"); } else { Customer cust = new Customer(); //create new customer record cust.Id = strId.Text; cust.first_name = strFName.Text; cust.last_name = strLName.Text; cust.birthdate = dateofBirth.Value; if (checkMale.Checked) { cust.gender = "זכר"; } else { cust.gender = "נקבה"; } cust.marital_status = maritalStatus.Text; cust.comments = strComments.Text; cust.email_address = emailAdd.Text; cust.status_cd = "פעיל"; dc.Customers.InsertOnSubmit(cust); // dc.SubmitChanges(); phone ph = new phone(); //create new phone record if (phoneNumH.Text != "" && areaCodeH.Text != "") { ph.phone_type = "בית"; ph.area_code = areaCodeH.Text; ph.phone_num = phoneNumH.Text; dc.phones.InsertOnSubmit(ph); // dc.SubmitChanges(); } phone ph1 = new phone(); //create new phone record if (phoneNumM.Text != "" && areaCodeM.Text != "") { ph1.phone_type = "נייד"; ph1.area_code = areaCodeM.Text; ph1.phone_num = phoneNumM.Text; dc.phones.InsertOnSubmit(ph1); // dc.SubmitChanges(); } dc.SubmitChanges(); if (ph != null) { customer_phone cph = new customer_phone(); cph.customer_id = strId.Text; cph.phone_id = ph.ID; cph.status = "פעיל"; cph.type = ph.phone_type; dc.customer_phones.InsertOnSubmit(cph); } if (ph1 != null) { customer_phone cph1 = new customer_phone(); cph1.customer_id = strId.Text; cph1.phone_id = ph1.ID; cph1.status = "פעיל"; cph1.type = ph1.phone_type; dc.customer_phones.InsertOnSubmit(cph1); } dc.SubmitChanges(); wh_address adr = new wh_address(); // new address record adr.city_name = cityName.Text; if (streetName.Text != "") { adr.street_name = streetName.Text; } if (houseNum.Text != "") { adr.house_num = int.Parse(houseNum.Text); } if (apartNum.Text != "") { adr.appartment_num = int.Parse(apartNum.Text); } if (neighbName.Text != "") { adr.neighborhood = neighbName.Text; } if (postCode.Text != "") { adr.zip_code = postCode.Text; } dc.wh_addresses.InsertOnSubmit(adr); dc.SubmitChanges(); customer_address custaddr = new customer_address();//new customer address record custaddr.customer_id = strId.Text; custaddr.address_id = adr.ID; custaddr.status = "פעיל"; dc.customer_addresses.InsertOnSubmit(custaddr); dc.SubmitChanges(); nextButton.Enabled = true; } } }