Beispiel #1
0
        public OpResult SaveTruck(Truck truck)
        {
            var      uow = Uow.Reposiotry <Truck>();
            OpResult op  = new OpResult()
            {
            };

            try
            {
                if (truck == null)
                {
                    op.Ok = false;
                    op.Errors.Add("truck can not be null");
                    return(op);
                }
                if (string.IsNullOrEmpty(truck.TruckName))
                {
                    op.Ok = false;
                    op.Errors.Add("Truck name is required!");
                    return(op);
                }
                if (truck.Id > 0)
                {
                    var existedTruck = uow.Get(truck.Id);
                    if (existedTruck != null)
                    {
                        uow.Detach(existedTruck);
                        existedTruck = Mapper.Map <Truck>(truck);
                        uow.Update(existedTruck);
                    }
                }
                else
                {
                    uow.Add(truck);
                }
                Uow.Commit();
            }
            catch (SqlException se)
            {
                op.Ok = false;
                op.Errors.Add(se.Message);
            }

            return(op);
        }