Esempio n. 1
0
        /// <summary>
        /// Creates a new Customer
        /// </summary>
        /// <param name="customerdetailBDO"></param>
        /// <returns></returns>
        public int CreateCustomerDetail(CustomerDetailBDO customerdetailBDO)
        {
            using (var scope = new TransactionScope())
            {
                var customer = new Customer
                {
                    CustomerTypeId = 1,
                    UserId         = "1", /*Hard Coded User ID will Switch when user going to create their own account*/
                    FirstName      = customerdetailBDO.FirstName,
                    LastName       = customerdetailBDO.LastName,
                    Email          = customerdetailBDO.Email,
                    Phone          = customerdetailBDO.Phone,
                    Mobile         = customerdetailBDO.Mobile,
                    AddressLine1   = customerdetailBDO.AddressLine1,
                    AddressLine2   = customerdetailBDO.AddressLine2,
                    AddressLine3   = customerdetailBDO.AddressLine3,
                    PostCode       = customerdetailBDO.PostCode,
                    CountryId      = customerdetailBDO.CountryId,
                    CityId         = customerdetailBDO.CityId,
                    CreatedDate    = DateTime.Now,
                };
                _unitOfWork.CustomerRepository.Insert(customer);
                _unitOfWork.Save();

                var customereventdetail = new CustomerEventDetail
                {
                    CustomerId  = customer.Id,
                    EventId     = 1,
                    Capacity    = customerdetailBDO.CustomerEventDetails.Capacity,
                    CostPerHead = customerdetailBDO.CustomerEventDetails.CostPerHead,
                };
                _unitOfWork.CustomerEventDetailRepository.Insert(customereventdetail);
                _unitOfWork.Save();

                foreach (var imageitem in customerdetailBDO.CustomerImages)
                {
                    var customerimage = new CustomerImage
                    {
                        CustomerId = customer.Id,
                        Image      = imageitem.Image
                    };
                    _unitOfWork.CustomerImageRepository.Insert(customerimage);
                    _unitOfWork.Save();
                }

                scope.Complete();
                return(customer.Id);
            }
        }
        // POST: api/Customer
        //[Route("Save")]
        public HttpResponseMessage Post([FromBody] CustomerDetailBDO customerdetails)
        {
            if (customerdetails != null)
            {
                int retcustomerid = this._customerdetailservice.CreateCustomerDetail(customerdetails);
                if (retcustomerid > 0)
                {
                    return(Request.CreateResponse(retcustomerid));
                }
                else
                {
                    return(Request.CreateResponse(0));
                }
            }

            return(Request.CreateErrorResponse(HttpStatusCode.NoContent, "Problem in saving in database."));
        }
        // GET: Banquets/Create
        public ActionResult Create()
        {
            CustomerDetailBDO model = new CustomerDetailBDO();

            model.Cities = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "Karachi", Value = "1"
                }
            };

            model.Countries = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "Pakistan", Value = "1"
                }
            };

            return(View("Create", model));
        }
Esempio n. 4
0
        /// <summary>
        /// Post and save banquet new record into the database
        /// </summary>
        /// <param name="banquestdetails"></param>
        /// <returns></returns>
        public async Task <string> SaveBanquestAsync(CustomerDetailBDO banquestdetails)
        {
            string getSucessfullOperation = string.Empty;
            string savebanquesturlstr     = string.Format("{0}{1}", apiurl, "api/BanquetDetailAPI/Post");

            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(savebanquesturlstr);
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                StringContent content = new StringContent(JsonConvert.SerializeObject(banquestdetails), Encoding.UTF8, "application/json");
                // HTTP POST
                HttpResponseMessage response = await httpClient.PostAsync(savebanquesturlstr, content);

                if (response.IsSuccessStatusCode)
                {
                    string data = await response.Content.ReadAsStringAsync();

                    getSucessfullOperation = JsonConvert.DeserializeObject <string>(data);
                }
            }
            return(getSucessfullOperation);
        }
 public async Task <ActionResult> Create(CustomerDetailBDO customerdetails)
 {
     try
     {
         if (ModelState.IsValid)
         {
             HttpFileCollectionBase files = HttpContext.Request.Files;
             int fileCount = files.Count;
             for (int i = 0; i < fileCount; i++)
             {
                 HttpPostedFileBase file     = files.Get(i);
                 string             filepath = @"\Content\BanquetImages\" + file.FileName;
                 file.SaveAs(@"E:\GitHub\BanquetSystem\BanquetSystem\BanquetSystem.UI\" + filepath);
                 customerdetails.CustomerImages[i].Image = filepath;
             }
             var SaveBanquestAsync = await service.SaveBanquestAsync(customerdetails);
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }