public ShipperViewModel Add(ShipperViewModel viewModel)
        {
            var model = Mapper.Map <ShipperViewModel, Shipper>(viewModel);

            _shipperRepository.Add(model);
            return(viewModel);
        }
Exemple #2
0
        public ActionResult ShipperMain(ShipperCondition condition)
        {
            ShipperAction    action    = new ShipperAction();
            ShipperViewModel viewModel = action.SearchGridView(condition);

            return(View(viewModel));
        }
Exemple #3
0
        public void CreateShipper(ShipperViewModel shipper)
        {
            var shipperInsert = Mapper.Map <ShipperViewModel, Shipper_M>(shipper);

            _shipperRepository.Add(shipperInsert);
            SaveShipper();
        }
Exemple #4
0
        public IHttpActionResult GetById(int id = 0)
        {
            try
            {
                var ship = db.Shippers.Find(id);
                if (ship == null)
                {
                    return(NotFound());
                }

                var data = new ShipperViewModel()
                {
                    ShipperID   = ship.ShipperID,
                    CompanyName = ship.CompanyName,
                    Phone       = ship.Phone
                };
                return(Ok(new
                {
                    success = true,
                    data = data
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Bir hata oluştur {ex.Message}"));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public static Shipper ToEntity(this ShipperViewModel viewModel)
        {
            return(viewModel == null ? null : new Shipper
            {
                Id = viewModel.Id,
                Company = viewModel.Company,
                //TransactionId = entity.TransactionId,
                Last_Name = viewModel.Last_Name,
                First_Name = viewModel.First_Name,
                Email_Address = viewModel.Email_Address,
                Job_Title = viewModel.Job_Title,
                Business_Phone = viewModel.Business_Phone,
                Home_Phone = viewModel.Home_Phone,
                Mobile_Phone = viewModel.Mobile_Phone,
                Fax_Number = viewModel.Fax_Number,
                Address = viewModel.Address,
                City = viewModel.City,
                State_Province = viewModel.State_Province,
                Zip_Postal_Code = viewModel.Zip_Postal_Code,
                Country_Region = viewModel.Country_Region,
                Web_Page = viewModel.Web_Page,
                Notes = viewModel.Notes,
                Attachments = viewModel.Attachments

                              //
                              //RowGuid = viewModel.RowGuid,
                              //ModifiedDate = viewModel.ModifiedDate
            });
        }
        public async Task <ActionResult> Shipper(string keyword, int?pageIndex)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                var getCRMShippersByConditionRequest = new GetShippersByConditionRequest();
                getCRMShippersByConditionRequest.SearchCondition = new ShipperSearchCondition()
                {
                    KeyWord = keyword
                };
                getCRMShippersByConditionRequest.PageSize = BasicFramework.Common.Constants.PAGESIZE;
                getCRMShippersByConditionRequest.PageIndex = pageIndex ?? 0;

                ShipperViewModel vm = new ShipperViewModel();
                var getCRMShippersByConditionResponse = new ShipperManagementService().GetShippersByCondition(getCRMShippersByConditionRequest);

                if (getCRMShippersByConditionResponse.IsSuccess)
                {
                    vm.CRMShipperCollection = getCRMShippersByConditionResponse.Result.ShipperCollection;
                    vm.PageIndex = getCRMShippersByConditionResponse.Result.PageIndex;
                    vm.PageCount = getCRMShippersByConditionResponse.Result.PageCount;
                }
                else
                {
                    throw new Exception(getCRMShippersByConditionResponse.Exception.Message);
                }
                return Json(vm, JsonRequestBehavior.AllowGet);
            }));
        }
Exemple #7
0
        public void UpdateShipper(ShipperViewModel shipper)
        {
            var shipperToRemove = _shipperRepository.GetById(shipper.ShipperC);
            var updateShipper   = Mapper.Map <ShipperViewModel, Shipper_M>(shipper);

            _shipperRepository.Delete(shipperToRemove);
            _shipperRepository.Add(updateShipper);
            SaveShipper();
        }
Exemple #8
0
        public IActionResult AddShipper([FromBody] ShipperViewModel shipperView)
        {
            var res = shipperOperations.AddShipper(shipperView);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            return(Created("", res));
        }
Exemple #9
0
        public IActionResult Update([FromBody] ShipperViewModel shipperView)
        {
            var res = shipperOperations.UpdateShipper(shipperView);

            if (res == null)
            {
                return(BadRequest());
            }
            return(Ok(res));
        }
Exemple #10
0
        public async Task <IActionResult> CreateShipperAsync([FromBody] ShipperViewModel value)
        {
            var response = new SingleModelResponse <ShipperViewModel>() as ISingleModelResponse <ShipperViewModel>;

            try
            {
                var entity = await Task.Run(() =>
                {
                    return(_RESTfulAPI_Repository.AddShipper(value.ToEntity()));
                });


                if (response.DidError == false)
                {
                    response.Model = entity.ToViewModel();
                }
            }
            catch (Exception ex)
            {
                string webRoot   = _hostingEnvironment.WebRootPath;
                string errorGuid = String.Format(Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 16));

                HttpContext.Session.SetString("ErrorGuid", errorGuid);
                ViewBag.ErrorGuid = HttpContext.Session.GetString("ErrorGuid");

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    using (StreamWriter w = new StreamWriter(webRoot + "\\log.txt", append: true))
                    {
                        Log.Logging(ex.ToString(), w, ViewBag.ErrorGuid);
                    }
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    using (StreamWriter w = new StreamWriter(webRoot + "/log.txt", append: true))
                    {
                        Log.Logging(ex.ToString(), w, ViewBag.ErrorGuid);
                    }
                }


                response.DidError = true;
                //response.ErrorMessage = ex.ToString();


                return(this.Json(new { timestamp = DateTime.Now, errorGuid = ViewBag.ErrorGuid, status = HttpStatusCode.InternalServerError, info = "Error logged in log file." }));
            }



            response.Info = "Client " + " " + HttpContext.Connection.RemoteIpAddress.ToString();

            return(response.ToHttpResponse());
        }
Exemple #11
0
        public Shipper AddShipper(ShipperViewModel shipperView)
        {
            Shipper shipper = new Shipper
            {
                CompanyName = shipperView.CompanyName,
                Phone       = shipperView.Phone,
                ShipperId   = shipperView.ShipperId
            };

            shipperRepository.Add(shipper);
            shipperRepository.SaveChanges();
            return(shipper);
        }
Exemple #12
0
        public async Task Must_Not_Add_Valid_Shipper()
        {
            await AuthanticateAccountAsync();

            var shipperViewModel = new ShipperViewModel()
            {
                CompanyName = string.Empty,
                Phone       = "(503) 555 - 9831"
            };
            var httpResponseMessage = _httpTestClient.PostAsJsonAsync("/api/shipper/add", shipperViewModel).Result;

            httpResponseMessage.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Exemple #13
0
        public async Task Must_Not_Update_Valid_Shipper()
        {
            await AuthanticateAccountAsync();

            var shipper = await CreateShipper();

            var shipperViewModel = new ShipperViewModel()
            {
                Id          = shipper.Id,
                CompanyName = string.Empty,
                Phone       = shipper.Phone,
            };
            var httpResponseMessage = _httpTestClient.PutAsJsonAsync("/api/shipper/update", shipperViewModel).Result;

            httpResponseMessage.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
 public JsonResult Save(ShipperViewModel info)
 {
     //insert
     return(Json(APIHelper.CallAPI <JsonResultData>("shipper/insert", new
                                                    MD_SHIPPER
     {
         NOTE = info.SHIPPERNOTE,
         TELEPHONE = info.SHIPPERTEL,
         ADDRESS = info.SHIPPERADDR,
         FAX = info.SHIPPERFAX,
         SHIPPERNAME = info.SHIPPERNAME,
         SHIPPERPRIMARY = info.SHIPPERPRIMARY,
         CREATEDUSER = LoginUser.Current.USERNAME,
         CREATEDDATE = DateTime.Now
     }), JsonRequestBehavior.AllowGet));
 }
 public ActionResult Add(ShipperViewModel shipper)
 {
     try
     {
         Shipper s = new Shipper();
         s.CompanyName = shipper.CompanyName;
         s.Phone       = shipper.Phone;
         db.Shippers.Add(s);
         db.SaveChanges();
         return(Json("ok", JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json("error", JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult Select(int id)
        {
            ShipperViewModel shipper = db.Shippers.Where(a => a.ShipperID == id).Select(a => new ShipperViewModel {
                ShipperID = a.ShipperID, CompanyName = a.CompanyName, Phone = a.Phone
            }).SingleOrDefault();

            if (shipper != null)
            {
                //TempData["ID"] = shipper.ShipperID;
                shipperID = shipper.ShipperID;
                return(Json(shipper, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("error", JsonRequestBehavior.AllowGet));
            }
        }
        public Shipper Add(ShipperViewModel model)
        {
            logger.LogInformation("ShipperOperation --- Add method started");

            Shipper shipper = new Shipper
            {
                ShipperId   = model.ShipperId,
                CompanyName = model.CompanyName,
                Phone       = model.Phone
            };

            repository.Shippers.Add(shipper);
            repository.SaveChanges();

            logger.LogInformation("ShipperOperation --- Add method finished");

            return(shipper);
        }
Exemple #18
0
        public Shipper UpdateShipper(ShipperViewModel shipperView)
        {
            Shipper shipper = new Shipper
            {
                ShipperId = shipperView.ShipperId
            };

            if (shipperView.CompanyName != null)
            {
                shipper.CompanyName = shipperView.CompanyName;
            }
            if (shipperView.Phone != null)
            {
                shipper.Phone = shipperView.Phone;
            }
            shipperRepository.Update(shipper);
            shipperRepository.SaveChanges();
            return(shipper);
        }
        public Shipper Edit(ShipperViewModel model)
        {
            logger.LogInformation("ShipperOperation --- Edit method started");

            Shipper shipper = new Shipper
            {
                ShipperId = model.ShipperId
            };

            shipper.Phone       = model.Phone;
            shipper.CompanyName = model.CompanyName;

            repository.Shippers.Update(shipper);
            repository.SaveChanges();

            logger.LogInformation("ShipperOperation --- Edit method finished");

            return(shipper);
        }
Exemple #20
0
        public IHttpActionResult Add([FromBody] ShipperViewModel model)
        {
            try
            {
                db.Shippers.Add(new Shipper()
                {
                    CompanyName = model.CompanyName,
                    Phone       = model.Phone
                });
                db.SaveChanges();

                return(Ok(new
                {
                    success = true,
                    message = "Shipper eklendi"
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Bir hata oluştu {ex.Message}"));
            }
        }
        public async Task <ActionResult> Shipper()
        {
            return(await Task.Run <ActionResult>(() =>
            {
                ShipperViewModel vm = new ShipperViewModel();

                var getCRMShippersByConditionRequest = new GetShippersByConditionRequest();
                getCRMShippersByConditionRequest.SearchCondition = new ShipperSearchCondition();
                getCRMShippersByConditionRequest.PageSize = BasicFramework.Common.Constants.PAGESIZE;
                getCRMShippersByConditionRequest.PageIndex = 0;

                var getCRMShippersByConditionResponse = new ShipperManagementService().GetShippersByCondition(getCRMShippersByConditionRequest);

                if (getCRMShippersByConditionResponse.IsSuccess)
                {
                    vm.CRMShipperCollection = getCRMShippersByConditionResponse.Result.ShipperCollection;
                    vm.PageIndex = getCRMShippersByConditionResponse.Result.PageIndex;
                    vm.PageCount = getCRMShippersByConditionResponse.Result.PageCount;
                }

                return View(vm);
            }));
        }
Exemple #22
0
        public IActionResult SaveEntity(ShipperViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(n => n.Errors);
                return(new BadRequestObjectResult(allErrors));
            }
            else
            {
                if (viewModel.Id == 0)
                {
                    _shipperService.Add(viewModel);
                }
                else
                {
                    _shipperService.Update(viewModel);
                }
            }

            _shipperService.Save();

            return(new OkObjectResult(viewModel));
        }
Exemple #23
0
        public IHttpActionResult Put(int id, ShipperViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != model.ShipperID)
            {
                return(BadRequest());
            }

            db.Entry(model).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                return(Ok(new
                {
                    success = true,
                    message = "Güncelleme işlemi başarılı"
                }));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!db.Categories.Any(x => x.CategoryID == id))
                {
                    return(NotFound());
                }
                else
                {
                    return(BadRequest($"Bir hata oluştu {ex.Message}"));
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #24
0
        public async Task <IActionResult> UpdateShipperAsync(Int32 id, [FromBody] ShipperViewModel value)
        {
            var response = new SingleModelResponse <ShipperViewModel>() as ISingleModelResponse <ShipperViewModel>;

            try
            {
                var entity = await Task.Run(() =>
                {
                    return(_RESTfulAPI_Repository.UpdateShipper(id, value.ToEntity()));
                });



                response.Model = entity.ToViewModel();
                response.Info  = "The record was updated successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Exemple #25
0
        public IActionResult Edit([FromBody] ShipperViewModel model)
        {
            var result = shipper.Edit(model);

            return(Ok(result));
        }
Exemple #26
0
        public async Task <IActionResult> Update([FromBody] ShipperViewModel ShipperViewModel)
        {
            var data = await _shipperAppService.UpdateShipper(ShipperViewModel);

            return(Ok(data));
        }
Exemple #27
0
        public IActionResult Add([FromBody] ShipperViewModel model)
        {
            var result = shipper.Add(model);

            return(Created("", result));
        }
 public void Put(ShipperViewModel shipper)
 {
     _shipperService.UpdateShipper(shipper);
 }
 public void Post(ShipperViewModel shipper)
 {
     _shipperService.CreateShipper(shipper);
 }
        public void Update(ShipperViewModel viewModel)
        {
            var model = Mapper.Map <ShipperViewModel, Shipper>(viewModel);

            _shipperRepository.Update(model);
        }