public HttpResponseMessage Create(HttpRequestMessage request, LocationViewModel locationViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newLocation = new Location();
                    newLocation.UpdateLocation(locationViewModel);
                    newLocation.CreatedDate = DateTime.Now;
                    newLocation.CreatedBy = User.Identity.Name;
                    _locationService.Add(newLocation);
                    _locationService.Save();

                    var responseData = Mapper.Map <Location, LocationViewModel>(newLocation);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Esempio n. 2
0
        public ActionResult RetriveDataFromAndroid(LocationViewModel locationVM)
        {
            var location = Mapper.Map <LocationViewModel, Location>(locationVM);

            locationService.Add(location);

            return(Json(new { succes = true }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
 public IActionResult Create([Bind("LocationID,BuildingId,FloorId,RoomId,RoomNo,IsWarehouse")] Location location)
 {
     if (ModelState.IsValid)
     {
         service.Add(location);
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["BuildingId"] = new List <SelectListItem>(service.GetSelectListBuildings());
     ViewData["FloorId"]    = new List <SelectListItem>(service.GetSelectListFloors());
     ViewData["RoomId"]     = new List <SelectListItem>(service.GetSelectListRooms());
     return(View(location));
 }
Esempio n. 4
0
        public async Task <IActionResult> Post([FromBody] Location location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _locationService.Add(location);
            await _unitOfWork.SaveChangesAsync();

            return(Ok(location));
        }
Esempio n. 5
0
        public ActionResult RetriveDataFromAndroid(LocationViewModel locationVM)
        {
            var location = Mapper.Map <LocationViewModel, Location>(locationVM);

            locationService.Add(location);

            List <string> codesArray = String.IsNullOrEmpty(locationVM.TroubleCodes) ? new List <string>() : locationVM.TroubleCodes.Split(new string[] { "\\n" }, StringSplitOptions.None).ToList();

            carService.AddTroubleCodesToCar(carService.GetById(Convert.ToInt32(locationVM.CarId)), codesArray);

            return(Json(new { succes = true }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public RedirectToActionResult Post(string Ip, string Country, string City)
        {
            var input = new LocationModel()
            {
                ip           = Ip,
                country_name = Country,
                city         = City
            };
            string connString = _config.GetSection("DbConnection").GetSection("ConnectionString").Value.ToString();
            var    response   = _locationService.Add(input, connString);

            return(RedirectToAction("Index"));
        }
        public IActionResult Add([FromBody] AddRequestModel requestModel, [FromHeader] string displayLanguage)
        {
            var responseModel = new Return <Location>();

            responseModel.DisplayLanguage = displayLanguage;
            try
            {
                var record = new Location();
                record.Name = requestModel.Name;

                var dbResult = _locationService.Add(record);

                if (dbResult > 0)
                {
                    responseModel.Data    = record; // oluşturulan entity bilgisinde id kolonu atanmış olur ve entity geri gönderiliyor
                    responseModel.Status  = ResultStatusCodeStatic.Success;
                    responseModel.Message = "Success";
                    responseModel.Success = true;
                    return(Ok(responseModel));
                }
                else
                {
                    responseModel.Status  = ResultStatusCodeStatic.InternalServerError;
                    responseModel.Message = "Could Not Be Saved";
                    responseModel.Success = false;
                    ReturnError error = new ReturnError();
                    error.Key            = "500";
                    error.Message        = "Could Not Be Saved";
                    error.Code           = 500;
                    responseModel.Errors = new List <ReturnError>();
                    responseModel.Errors.Add(error);
                    responseModel.Data = null; //hata oluştugundan dolayı Data null olarak dönülür.
                    return(StatusCode(StatusCodes.Status500InternalServerError, responseModel));
                }
            }
            catch (Exception ex)
            {
                responseModel.Status  = ResultStatusCodeStatic.InternalServerError;
                responseModel.Message = "An error occurred";
                responseModel.Success = false;
                ReturnError error = new ReturnError();
                error.Key            = "500";
                error.Message        = ex.Message;
                error.Code           = 500;
                responseModel.Errors = new List <ReturnError>();
                responseModel.Errors.Add(error);
                responseModel.Data = null; //hata oluştugundan dolayı Data null olarak dönülür.
                return(StatusCode(StatusCodes.Status500InternalServerError, responseModel));
            }
        }
        public IActionResult Post([FromBody] LocationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = locationService.Add(model);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response.ReturnedId));
        }
        public async Task <IActionResult> Create(LocationCreateDto categoryDto)
        {
            if (await _categoryService.CheckExists(categoryDto.ID))
            {
                return(BadRequest("Location ID already exists!"));
            }
            //var username = User.FindFirst(ClaimTypes.Name).Value;
            //categoryIngredientDto.Updated_By = username;
            if (await _categoryService.Add(categoryDto))
            {
                return(NoContent());
            }

            throw new Exception("Creating the category failed on save");
        }
Esempio n. 10
0
        public bool ImportLoctionExcel(ExcelWorksheet locationSheet)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
                                                                 new System.TimeSpan(0, 60, 0)))
            {
                try
                {
                    var colCount = locationSheet.Dimension.End.Column;
                    var rowCount = locationSheet.Dimension.End.Row;
                    for (int i = 2; i <= rowCount; i++)
                    {
                        Location location;
                        string   name = locationSheet.Cells[i, 1].Value.ToString();

                        if (_locationService.GetLocationByName(name) != null)
                        {
                            location              = _locationService.GetLocationByName(name);
                            location.Name         = locationSheet.Cells[i, 1].Value.ToString();
                            location.LocationCode = locationSheet.Cells[i, 2].Value.ToString();
                            location.Description  = locationSheet.Cells[i, 3].Value.ToString();
                            string campusName = locationSheet.Cells[i, 4].Value.ToString();
                            location.CampusID = _campusService.GetCampusCode(campusName).ID;
                            location.Active   = true;
                            _locationService.Update(location);
                            _locationService.SaveChanges();
                        }
                        else
                        {
                            location              = new Location();
                            location.Name         = locationSheet.Cells[i, 1].Value.ToString();
                            location.LocationCode = locationSheet.Cells[i, 2].Value.ToString();
                            location.Description  = locationSheet.Cells[i, 3].Value.ToString();
                            string campusName = locationSheet.Cells[i, 4].Value.ToString();
                            location.CampusID = _campusService.GetCampusCode(campusName).ID;
                            location.Active   = true;
                            _locationService.Add(location);
                            _locationService.SaveChanges();
                        }
                    }
                    scope.Complete();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Esempio n. 11
0
        public IActionResult Post([FromBody] CreateEditViewModel model)
        {
            var location = new Location();

            if (model is null)
            {
                return(BadRequest("Location is null."));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var locationMapper = _mapper.Map(model, location);

            _locationProvider.Add(locationMapper);
            return(Ok(locationMapper));
        }
Esempio n. 12
0
        public ActionResult Create(Location model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    LocationService.Add(model);
                    LocationService.SaveChanges();
                }
                else
                {
                    return(View(model));
                }
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult <ItemResponse <int> > Create(LocationAddRequest model)
        {
            ObjectResult result = null;

            try
            {
                int userId = _authService.GetCurrentUserId();

                int id = _service.Add(model, userId);

                ItemResponse <int> response = new ItemResponse <int>();
                response.Item = id;

                result = StatusCode(200, response);
            }
            catch (Exception ex)
            {
                ErrorResponse response = new ErrorResponse(ex.Message);
                result = StatusCode(500, response);
            }

            return(result);
        }
Esempio n. 14
0
        public ActionResult Add(Models.Location.AddViewModel modell)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ErrorMessage = "Error.";
                return(View(modell));
            }

            Business.Models.Location.AddRequestModel location = new Business.Models.Location.AddRequestModel();
            location.Name = modell.Name;

            var apiResponseModel = _locationService.Add(location).Result;

            if (apiResponseModel.Status == ResultStatusCodeStatic.Success)
            {
                return(RedirectToAction(nameof(LocationController.List)));
            }
            else
            {
                ViewBag.ErrorMessage = apiResponseModel.Message != null ? apiResponseModel.Message : "Kaydedilemedi.";//todo: kulturel olacak NotSaved
                return(View(modell));
            }
        }
        public IHttpActionResult Post(Location location)
        {
            long retId;

            try
            {
                if (location == null)
                {
                    throw new ArgumentException("Location model is null.");
                }

                retId = _locationService.Add(location);
                if (retId == 0)
                {
                    Log.Info($"{typeof(LocationController).FullName}||{UserEnvironment}||Add record not successful, Location Code is duplicate.");
                    return(Content(HttpStatusCode.Forbidden, "Location Code is Duplicate"));
                }

                var    response = this.Request.CreateResponse(HttpStatusCode.Created);
                string test     = JsonConvert.SerializeObject(new
                {
                    id      = retId,
                    message = "Location added"
                });
                response.Content = new StringContent(test, Encoding.UTF8, "appliation/json");
                Log.Info($"{typeof(LocationController).FullName}||{UserEnvironment}||Add record successful.");

                return(ResponseMessage(response));
            }
            catch (Exception e)
            {
                Log.Error(typeof(LocationController).FullName, e);

                return(Content(HttpStatusCode.NotAcceptable, e.Message));
            }
        }