Ejemplo n.º 1
0
        public ActionResult Add(Models.Appliance.AddViewModel model)
        {
            // birden fazla cihaz ekleme butonu
            if (model.SubmitType == "AddApplianceSerial")
            {
                ModelState.Clear();

                if (model.Appliances == null)
                {
                    model.Appliances = new List <ApplianceModel>();
                }

                model.Appliances.Add(new ApplianceModel()
                {
                    Name    = null,
                    Barcode = null
                });

                return(View(model));
            }
            else if (model.SubmitType.StartsWith("DeleteApplianceSerial"))
            {
                int selectedIndex = Convert.ToInt32(model.SubmitType.Replace("DeleteApplianceSerial", ""));

                ModelState.Clear();

                model.Appliances.RemoveAt(selectedIndex);
                return(View(model));
            }

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


            foreach (var item in model.Appliances)
            {
                Business.Models.Appliance.Appliance appliance = new Business.Models.Appliance.Appliance();
                appliance.Name    = item.Name;
                appliance.Barcode = item.Barcode;
                var apiResponseModel = _applianceService.Add(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar, appliance);
                if (apiResponseModel.ResultStatusCode != ResultStatusCodeStatic.Success)
                {
                    ViewBag.ErrorMessage     = apiResponseModel.ResultStatusMessage != null ? apiResponseModel.ResultStatusMessage : "Kaydedilemedi.";//todo: kulturel olacak NotSaved
                    ViewBag.ErrorMessageList = apiResponseModel.ErrorMessageList;
                    return(View(model));
                }
            }
            return(RedirectToAction(nameof(ApplianceController.List)));
        }
Ejemplo n.º 2
0
        public IActionResult Add([FromBody] AddRequestModel requestModel, [FromHeader] string displayLanguage)
        {
            var responseModel = new ApiResponseModel <Appliance>();

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

                var dbResult = _applianceService.Add(record);

                if (dbResult > 0)
                {
                    responseModel.Data                = record; // oluşturulan entity bilgisinde id kolonu atanmış olur ve entity geri gönderiliyor
                    responseModel.ResultStatusCode    = ResultStatusCodeStatic.Success;
                    responseModel.ResultStatusMessage = "Success";
                    return(Ok(responseModel));
                }
                else
                {
                    responseModel.ResultStatusCode    = ResultStatusCodeStatic.Error;
                    responseModel.ResultStatusMessage = "Could Not Be Saved";
                    responseModel.Data = null;
                    return(StatusCode(StatusCodes.Status500InternalServerError, responseModel));
                }
            }
            catch (Exception ex)
            {
                responseModel.ResultStatusCode    = ResultStatusCodeStatic.Error;
                responseModel.ResultStatusMessage = ex.Message;
                responseModel.Data = null;
                return(StatusCode(StatusCodes.Status500InternalServerError, responseModel));
            }
        }