public async Task <IActionResult> Create(CatererViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var caterer = _mapper.Map <Caterer>(model);
            await _service.Add(caterer);

            if (!ValidOperation())
            {
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create
            (CatererViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newLocation = new GoogleMapDTO
                {
                    Address = model.Address,
                    Lat     = model.Lat,
                    Long    = model.Long
                };
                var userID =
                    _userManager.GetUserId(User);
                var newCaterer = new CatererDTO
                {
                    CatererID            = userID,
                    Address              = model.Address,
                    Lat                  = model.Lat,
                    Long                 = model.Long,
                    CateringFacilitiName = model.CateringFacilitiName,
                    CatererName          = model.CatererName
                };

                newLocation = await _GoogleMapSvc.Add(newLocation);

                var IDCateringFacility = await _CatererSvc.PostCaterer(newCaterer);


                List <Item> itemList = await _ExcelSvc.Get(model.FormDocument, IDCateringFacility);



                await _ItemSvc.PostItem(itemList);


                var QRImage = await _QRCodeSvc.GetQRImage(newLocation);



                return(File(QRImage.QRImageInBytes, System.Net.Mime.MediaTypeNames.Application.Octet, "MyQRCode.jpg"));
            }

            return(View("Index"));
        }
        public async Task <IActionResult> UpdateAddress(CatererViewModel model)
        {
            ModelState.Remove("Name");
            ModelState.Remove("Document");

            if (!ModelState.IsValid)
            {
                return(PartialView("_UpdateAddress", model));
            }

            await _service.UpdateAddress(_mapper.Map <Address>(model.Address));

            if (!ValidOperation())
            {
                return(PartialView("_UpdateAddress", model));
            }

            var url = Url.Action("GetAddress", "Caterers", new { id = model.Id });

            return(Json(new { success = true, url }));
        }
        public async Task <IActionResult> Edit(Guid id, CatererViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var caterer = _mapper.Map <Caterer>(model);
            await _service.Update(caterer);

            if (!ValidOperation())
            {
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public async Task <string> PostExcel(CatererViewModel model)
        {
            var uri = _api.PostExcel();



            var request = new HttpRequestMessage(HttpMethod.Post, uri);

            var bytes = await GetBytes(model.FormDocument);


            MealsDTO mealsDoc = new MealsDTO();

            mealsDoc.Document = bytes;


            request.Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(mealsDoc));

            request.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");

            var client = _httpClientFactory;

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


            var response = await client.SendAsync(request);

            // GoogleMapDTO locations = null;
            //if (response.IsSuccessStatusCode)
            //{
            //    var responseStream = await response.Content.ReadAsStringAsync();
            //    qRCodes = JsonConvert.DeserializeObject<QRDataCatering>(responseStream);
            //}

            //Checking the response is successful or not which is sent using HttpClient
            //TODO STO VRATITI AKO UPIT BUDE NEUSPIJESAN "Umjesto Exception"
            return(response.IsSuccessStatusCode ? JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync()) : throw new Exception("Error cancelling order, try later."));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Import()
        {
            string json = null;

            CatererViewModel caterer = new CatererViewModel();


            IFormFile file = Request.Form.Files[0];

            caterer.FormDocument = file;
            //string tableData=  ExcelUtility.DisplayTable(file);

            string tableData = await _ExcelSvc.PostExcel(caterer);

            //_ExcelSvc.Get();


            return(RedirectToAction("Registration", "Caterer", new
            {
                test = tableData
            }));

            //return this.Content(tableData);
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Export(CatererViewModel caterer)
        {
            string responseContent = await _ExcelSvc.PostExcel(caterer);

            return(this.Content(responseContent));
        }