예제 #1
0
        public void Delete(TruckModel truckModel)
        {
            try
            {
                if (ValidateDelete(truckModel))
                {
                    return;
                }

                Common.DAL.Truck truck = dbContext.Trucks.Where(x => x.Id == truckModel.Id).FirstOrDefault();

                if (truck == null)
                {
                    base.HandleError(truckModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                    return;
                }

                dbContext.Trucks.Remove(truck);

                base.SaveChanges();

                truckModel.AddSuccess(Resources.TruckDeletedSuccessfully, LookUps.SuccessType.Full);
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                base.HandleError(truckModel, CommonLayer.LookUps.ErrorType.Business, null, Resources.RefrenceDeleteError);
                base.UndoUpdates();
            }
            catch (Exception ex)
            {
                base.HandleError(truckModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
예제 #2
0
        public async Task <ActionResult <TruckModel> > PostTruckModel(TruckModel truckModel)
        {
            _context.trucks.Add(truckModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTruckModel", new { id = truckModel.Id }, truckModel));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Description")] TruckModel truckModel)
        {
            if (id != truckModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(truckModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TruckModelExists(truckModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(truckModel));
        }
        public void Get_all_future_hops_should_return_HopArrivalModel_list()
        {
            // Arrange
            HopArrivalModel latest = new HopArrivalModel()
            {
            };
            TruckModel closestTruck = new TruckModel()
            {
            };
            RecipientModel recipient = new RecipientModel
            {
                FirstName  = "Rudi",
                LastName   = "Recipient",
                Street     = "Poststraße",
                PostalCode = "A-1070",
                City       = "Poststadt"
            };
            ParcelModel parcel = new ParcelModel {
                Recipient = recipient, Weight = 1.0f
            };

            // Act
            var result = warehouse.GetAllFutureHops(latest, closestTruck, parcel);

            // Assert
            Assert.IsInstanceOfType(result, typeof(IList <HopArrivalModel>));
        }
예제 #5
0
        public TruckModelSaveUpdateViewModel SearchTruckModel(TruckModelSaveUpdateViewModel model)
        {
            var modelSearchResult = new TruckModel();

            if (!string.IsNullOrEmpty(model.Description))
            {
                //Search for model in DB only if numbers and letters in model name
                if (!_validate.Alphanumeric(model.Description))
                {
                    model.IsValid = false;
                }
                else
                {
                    modelSearchResult = _truckModelContext.Collection().Where(m => m.ModelDescription == model.Description).FirstOrDefault();
                    if (modelSearchResult == null)
                    {
                        model.ExistInDB = false;
                    }
                    else
                    {
                        model.Id             = modelSearchResult.Id;
                        model.Description    = modelSearchResult.ModelDescription;
                        model.ManufacturerId = modelSearchResult.TruckManufacturerId;
                        var manufacturer = _truckManufacturerContext.Collection().Where(m => m.Id == modelSearchResult.TruckManufacturerId).FirstOrDefault();
                        model.ManufacturerDescription = manufacturer.ManufacturerDescription;
                    }
                }
            }
            return(model);
        }
예제 #6
0
        public List <TruckModel> GetTruckList(int pageIndex, int pageSize, string number, DateTime dateTime, out int total)
        {
            total = 0;
            QueryPageModel queryPageModel = new QueryPageModel();

            queryPageModel.OrderBy   = "TruckID";
            queryPageModel.PageIndex = pageIndex;
            queryPageModel.PageSize  = pageSize;
            queryPageModel.QuerySql  = @"(select * from [Truck]) u where 1=1 {0} )";
            string     sqlWhere = "";
            TruckModel model    = new TruckModel();

            if (!string.IsNullOrEmpty(number))
            {
                sqlWhere    += " and Number like @Number";
                model.Number = number + "%";
            }
            if (dateTime > new DateTime(1950, 1, 1))
            {
                sqlWhere         += " and CheckInTime < @CheckInTime";
                model.CheckInTime = dateTime;
            }
            queryPageModel.QuerySql = string.Format(queryPageModel.QuerySql, sqlWhere);

            var result = PageDataHelper.QueryWithPage <TruckModel>(queryPageModel, model);

            total = PageDataHelper.QueryTotalCount(queryPageModel, model);
            return(result.ToList());
        }
예제 #7
0
        public void Edit(TruckModel truckModel)
        {
            try
            {
                Common.DAL.Truck truck = dbContext.Trucks.Where(x => x.Id == truckModel.Id).FirstOrDefault();

                if (truck == null)
                {
                    base.HandleError(truckModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                    return;
                }

                if (Validate(truckModel))
                {
                    return;
                }

                TruckMapper.Map(dbContext, truckModel, truck);

                base.SaveChanges();

                truckModel.AddSuccess(Resources.TruckUpdatedSuccessfully, LookUps.SuccessType.Full);
            }
            catch (Exception ex)
            {
                base.HandleError(truckModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
        protected async void GetPendingList()
        {
            records.Clear();
            string url = "";

            if (Title.Equals("Cargo Receiving"))
            {
                url = ControllerUtil.getPendingReceivingURL();
            }
            else if (Title.Equals("Cargo Loading"))
            {
                url = ControllerUtil.getPendingLoadURL();
            }
            else if (Title.Equals("Cargo Measuring"))
            {
                url = ControllerUtil.getPendingReceivingURL();
            }

            var content = await CommonFunction.CallWebService(0, null, Ultis.Settings.SessionBaseURI, url, this);

            clsResponse pending_response = JsonConvert.DeserializeObject <clsResponse>(content);

            if (pending_response.IsGood)
            {
                App.Database.DeleteTruckModel();

                List <clsTruckingModel> trucks = JObject.Parse(content)["Result"].ToObject <List <clsTruckingModel> >();

                foreach (clsTruckingModel truck in trucks)
                {
                    string     summary = "";
                    TruckModel record  = new TruckModel();

                    record.TruckId  = truck.TruckId;
                    record.RecordId = truck.Id;

                    foreach (clsCaptionValue truckValue in truck.Summary)
                    {
                        summary += truckValue.Caption + "  :  " + truckValue.Value + "\r\n" + "\r\n";

                        if (truckValue.Caption.Equals("Job No."))
                        {
                            record.JobNo = truckValue.Value;
                        }
                    }

                    record.Summary = summary;

                    //App.Database.SaveTruckModelAsync(record);
                    records.Add(record);
                }

                loadPendingList();
            }
            else
            {
                await DisplayAlert("JsonError", pending_response.Message, "OK");
            }
        }
예제 #9
0
        // GET: Localizacao
        public ActionResult Index()
        {
            TruckModel model  = new TruckModel();
            Pessoa     pessoa = Session["truck"] as Pessoa;
            Truck      truck  = model.Read(pessoa.IdPessoa);

            return(View(truck));
        }
예제 #10
0
        public TruckModel Delete(int id)
        {
            TruckModel tm = db.TruckModels.FirstOrDefault(x => x.Id == id);

            db.TruckModels.Remove(tm);
            db.SaveChanges();
            return(tm);
        }
예제 #11
0
        public TruckModel Update(TruckModel entity)
        {
            TruckModel UpdateEntity = db.TruckModels.FirstOrDefault(x => x.Id == entity.Id);

            UpdateEntity.ModelCode = entity.ModelCode;
            db.SaveChanges();
            return(UpdateEntity);
        }
예제 #12
0
        private bool Validate(TruckModel truckModel)
        {
            if (dbContext.Trucks.Any(x => x.Name == truckModel.Name && x.Id != truckModel.Id.ToString()))
            {
                base.HandleError(truckModel, CommonLayer.LookUps.ErrorType.Business, null, string.Format(Resources.AlreadyExists, truckModel.GetDisplayName(x => x.Name)), truckModel.nameof(x => x.Name));
            }

            return(truckModel.HasErrorByType());
        }
 public async Task CreateTruck([FromBody] TruckModel model)
 {
     await _truckService.CreateTruck(new Trucks
     {
         Height = model.Height,
         Width  = model.Width,
         Number = model.Number
     });
 }
예제 #14
0
 public void PrepareTruckModel(TruckModel truckModel)
 {
     try
     {
     }
     catch (Exception ex)
     {
         base.HandleError(truckModel, CommonLayer.LookUps.ErrorType.Critical, ex);
     }
 }
예제 #15
0
        public IActionResult Index()
        {
            TruckModel tm = new TruckModel();
            Truck      t  = new Truck();

            t  = _translator.Translate <Truck>(tm);
            tm = _translator.Translate <TruckModel>(t);
            ViewData["TruckTypes"] = _trucksContext.GetAllTruckTypes();
            ViewData["TruckSizes"] = _trucksContext.GetAllTruckSizes();
            return(View());
        }
예제 #16
0
 public TruckLoadModel()
 {
     TruckModel     = new TruckModel(false);
     DriverModel    = new DriverModel(false);
     CompanyModel   = new CompanyModel(false);
     StatusModel    = new StatusModel(false);
     FromStateModel = new USAStateModel(false);
     ToStateModel   = new USAStateModel(false);
     StatesList     = new List <SelectListItem>();
     StatusesList   = new List <SelectListItem>();
 }
예제 #17
0
        public IActionResult Edit(int id)
        {
            TruckModel          tm   = db.GetSingle(id);
            TruckModelViewModel tmvm = new TruckModelViewModel
            {
                Value = tm.Id.ToString(),
                Text  = tm.ModelCode
            };

            return(View(tmvm));
        }
예제 #18
0
        public void PostNewTruckModelToDB(TruckModelSaveUpdateViewModel truckModel)
        {
            var truckModelToInsert = new TruckModel();

            truckModelToInsert.ModelDescription    = truckModel.Description;
            truckModelToInsert.TruckManufacturerId = truckModel.ManufacturerId;

            _truckModelContext.Insert(truckModelToInsert);
            _truckModelContext.Commit();
            _logger.Info("Inserted record Id " + truckModelToInsert.Id + " into Table " + tableNameUsedByLogger);
        }
        public async Task <IActionResult> Create([Bind("Id,Description")] TruckModel truckModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(truckModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(truckModel));
        }
예제 #20
0
        public static List <TruckModel> update(TruckModel truck)
        {
            var response = new RequestAPI()
                           .addClient(new RestClient(urlRequest))
                           .addRequest(new RestRequest("truck/update/", Method.GET, DataFormat.Json))
                           .addHeader(new KeyValuePair <string, object>("Accept", "application/json"))
                           .addBodyData(truck)
                           .buildRequest();

            return(RequestAPI.deserilizeProject <List <TruckModel> >(response));
        }
예제 #21
0
 public int SaveTruckModelAsync(TruckModel record)
 {
     record.owner = Ultis.Settings.SessionUserId;
     if (record.tableID != 0)
     {
         return(database.Update(record));
     }
     else
     {
         return(database.Insert(record));
     }
 }
예제 #22
0
        public ActionResult Index(FormCollection form)
        {
            Truck truck = new Truck();

            truck.NomeTruck = form["nomeTruck"];

            if (truck.NomeTruck == "")
            {
                Cliente cliente = new Cliente();
                cliente.Nome       = form["name"];
                cliente.Telefone   = form["phone"];
                cliente.Celular    = form["cel"];
                cliente.Email      = form["email"];
                cliente.Senha      = form["senha"];
                cliente.TipoPessoa = 1;
                cliente.Status     = 1;
                cliente.CPFCNPJ    = form["cpf"];

                using (ClienteModel model = new ClienteModel())
                {
                    model.Create(cliente);
                }
                return(Redirect("Home"));
            }
            else
            {
                truck.Nome           = form["name"];
                truck.Telefone       = form["phone"];
                truck.Celular        = form["cel"];
                truck.Email          = form["email"];
                truck.Senha          = form["senha"];
                truck.TipoPessoa     = 0;
                truck.Status         = 1;
                truck.CNPJ           = form["cnpj"];
                truck.DescricaoTruck = form["descricao"];
                truck.CEP            = form["cep"];
                truck.Estado         = form["uf"];
                truck.Cidade         = form["cidade"];
                truck.Bairro         = form["bairro"];
                truck.Endereco       = form["endereco"];
                truck.Numero         = form["numero"];
                truck.Referencia     = form["referencia"];
                truck.Latitude       = "1";
                truck.Longitude      = "1";
                truck.Logo           = 123;

                using (TruckModel model = new TruckModel())
                {
                    model.Create(truck);
                }
                return(Redirect("Login"));
            }
        }
        public void CreateTruckModelViewModel(CreateTruckModelViewModel truckModel)
        {
            TruckModel tr = new TruckModel(truckModel.ModelYear,
                                           truckModel.Color,
                                           truckModel.Engine,
                                           truckModel.Potence,
                                           truckModel.ResponsableId,
                                           truckModel.Status);

            _contextDb.Add(tr);
            _contextDb.SaveChanges();
        }
예제 #24
0
        public ActionResult Create(BaseModel baseModel)
        {
            TruckModel truckModel = new TruckModel();

            truckModel.CopyBaseModel(baseModel);

            using (TruckBAL truckBAL = new TruckBAL(ContextInfo))
            {
                truckBAL.PrepareTruckModel(truckModel);
            }

            return(View("Create", truckModel));
        }
예제 #25
0
        public ActionResult ViewTruck(string id)
        {
            TruckModel truckModel = new TruckModel();

            truckModel.Id = id;

            using (TruckBAL truckBAL = new TruckBAL(ContextInfo))
            {
                truckBAL.GetTruckModel(truckModel);
            }

            return(View(truckModel));
        }
예제 #26
0
        public static void Map(LMYFrameWorkMVCEntities dbContext, List <Truck> src, List <TruckModel> dest)
        {
            if (src == null || dest == null)
            {
                return;
            }

            foreach (Truck truck in src)
            {
                TruckModel truckModel = new TruckModel();
                Map(dbContext, truck, truckModel);
                dest.Add(truckModel);
            }
        }
예제 #27
0
        public static void Map(LMYFrameWorkMVCEntities dbContext, TruckModel src, Truck dest)
        {
            if (src == null || dest == null)
            {
                return;
            }

            dest.CopyPropertyValues(src);

            if (!string.IsNullOrEmpty(src.OnBuyDateString))
            {
                dest.OnBuyDate = src.OnBuyDateString.ConvertToDateTime();
            }
        }
        public void Validate_truck_model_should_return_true()
        {
            // Arrange
            TruckModel truck = new TruckModel()
            {
                Code = "TMOC", Parent = null, Duration = 0.5m, Latitude = 14, Longitude = 40, NumberPlate = "MOCKTRK-1", Radius = 10m
            };

            // Act
            var result = _wl.ValidateTruckModel(truck);

            // Assert
            Assert.IsTrue(result);
        }
예제 #29
0
        public ActionResult Delete(TruckModel truckModel)
        {
            using (TruckBAL truckBAL = new TruckBAL(ContextInfo))
            {
                truckBAL.Delete(truckModel);

                if (truckModel.HasErrorByType())
                {
                    truckBAL.GetTruckModel(truckModel);
                    //     truckBAL.PrepareTruckModel(truckModel);
                }
            }

            return(View(truckModel));
        }
예제 #30
0
        // GET: Truck/Edit/5
        public ActionResult Edit(string id, BaseModel baseModel)
        {
            TruckModel truckModel = new TruckModel();

            truckModel.CopyBaseModel(baseModel);
            truckModel.Id = id;

            using (TruckBAL truckBAL = new TruckBAL(ContextInfo))
            {
                truckBAL.GetTruckModel(truckModel);
                truckBAL.PrepareTruckModel(truckModel);
            }

            return(View(truckModel));
        }