public async Task <IActionResult> GetBills([FromBody] TblTourBills tourBills)
        {
            try
            {
                var _clientList = new TouresHelper().GetToureBills(tourBills?.EmpId, tourBills?.Tourid);
                if (_clientList.Count > 0)
                {
                    dynamic expando = new ExpandoObject();
                    expando.Clients = _clientList;
                    return(Ok(new APIResponse()
                    {
                        STATUS = APISTATUS.PASS.ToString(), Response = expando
                    }));
                }

                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = "No Bills found."
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = ex.Message
                }));
            }
        }
Exemple #2
0
        public TblTourBills AddToureBills(TblTourBills tblTourBills)
        {
            try
            {
                tblTourBills.AppliedDate = DateTime.Now;
                using (MobileContext context = new MobileContext())
                {
                    context.TblTourBills.Add(tblTourBills);
                    if (context.SaveChanges() > 0)
                    {
                        return(tblTourBills);
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // public async Task<IActionResult> UploadBills([FromBody]TblTourBills tblTourBills)
        public async Task <IActionResult> UploadBills([FromForm(Name = "BillsImage")] IFormFile Image, [FromForm(Name = "touid")] string toureid, [FromForm(Name = "employeeCode")] string employeeCode)
        {
            if (Image == null)
            {
                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = "Request is empty."
                }));
            }
            if (string.IsNullOrEmpty(employeeCode))
            {
                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = "Request is empty."
                }));
            }
            try
            {
                string dateFile = string.Empty, filePath = string.Empty, fileName = string.Empty;
                var    image = Image;

                var uploads = Path.Combine(_webHostEnvironment.WebRootPath, "Images");

                if (image.Length > 0)
                {
                    dateFile = $"{DateTime.Now.Day}{DateTime.Now.Month}{DateTime.Now.Year}{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}{DateTime.Now.Millisecond}";
                    fileName = dateFile + image.FileName;

                    filePath = Path.Combine(uploads, fileName);

                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await image.CopyToAsync(fileStream);
                    }
                }


                var tblTourBills = new TblTourBills();
                tblTourBills.Tourid       = toureid?.Replace("\"", string.Empty)?.Trim();
                tblTourBills.EmpId        = employeeCode?.Replace("\"", string.Empty)?.Trim();
                tblTourBills.ImageContent = $"{applicationConfig.Value.ImageFilePath}Images/" + fileName;

                var _tblTourBills = new TouresHelper().AddToureBills(tblTourBills);
                if (_tblTourBills != null)
                {
                    dynamic expando = new ExpandoObject();
                    expando.Bills = _tblTourBills;
                    return(Ok(new APIResponse()
                    {
                        STATUS = APISTATUS.PASS.ToString(), Response = expando
                    }));
                }

                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = "Failed to upload bills."
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = ex.InnerException
                }));
            }
        }