Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the <see cref="DeliveryNote"/>.
        /// </summary>
        /// <param name="deliveryNote">The delivery note which will be canceled.</param>
        public void ActiveDeliveryNote(DeliveryNotePrimitive deliveryNotePrimitive)
        {
            try
              {
            using (SmartWorkingEntities context = new SmartWorkingEntities())
            {
              DeliveryNote deliveryNote = deliveryNotePrimitive.GetEntity();

              DeliveryNote existingObject = context.DeliveryNotes.Where(x => x.Id == deliveryNote.Id).FirstOrDefault();

              //no record of this item in the DB, item being passed in has a PK
              if (existingObject == null)
              {
            throw new Exception("Only exists delivery note can be canceled.");
              }

              deliveryNote.DeactivationReason = string.Empty;
              deliveryNote.Deactivated = null;
              context.DeliveryNotes.ApplyCurrentValues(deliveryNote);

              context.SaveChanges();
            }
              }
              catch (Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the <see cref="DeliveryNote"/>.
        /// </summary>
        /// <param name="deliveryNote">The delivery note which will be updated.</param>
        public DeliveryNotePrimitive CreateOrUpdateDeliveryNote(DeliveryNotePrimitive deliveryNotePrimitive)
        {
            try
              {
            using (SmartWorkingEntities context = new SmartWorkingEntities())
            {
              DeliveryNote deliveryNote = deliveryNotePrimitive.GetEntity();

              DeliveryNote existingObject = context.DeliveryNotes.Where(x => x.Id == deliveryNote.Id).FirstOrDefault();

              //no record of this item in the DB, item being passed in has a PK
              if (existingObject == null && deliveryNote.Id > 0)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(new Exception("Błąd zapisu do bazy")),
                                                        "Obiekt nie istniał w bazie, a jego Id jest większe od 0.");
              }

              DeliveryNote checkingNumber =
            context.DeliveryNotes.Where(x => x.Number == deliveryNote.Number && x.Year == deliveryNote.Year).
              FirstOrDefault();

              //Item has no PK value, must be new);)
              if (deliveryNote.Id <= 0)
              {
            deliveryNote.DateDrawing = DateTime.Now;
            //deliveryNote.Number = GetNextDeliveryNumber();
            if (checkingNumber != null)
            {
              throw new Exception("Ten numer WZ'tki juz istnieje!");
            }
            context.DeliveryNotes.AddObject(deliveryNote);

              }
              //Item was retrieved, and the item passed has a valid ID, do an update
              else
              {
            if (checkingNumber != null && checkingNumber.Id != deliveryNote.Id)
            {
              throw new Exception("Ten numer WZ'tki juz istnieje!");
            }
            context.DeliveryNotes.ApplyCurrentValues(deliveryNote);
              }

              context.SaveChanges();

              return deliveryNote;
            }
              }
              catch (Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }
Ejemplo n.º 3
0
        public static DeliveryNotePrimitive GetPrimitive(this DeliveryNote entity)
        {
            DeliveryNotePrimitive primitive = new DeliveryNotePrimitive();

                primitive.Id = entity.Id;

                primitive.Driver_Id = entity.Driver_Id;

                primitive.DateDrawing = entity.DateDrawing;

                primitive.DateOfArrival = entity.DateOfArrival;

                primitive.Drawer = entity.Drawer;

                primitive.Car_Id = entity.Car_Id;

                primitive.Amount = entity.Amount;

                primitive.Order_Id = entity.Order_Id;

                primitive.Deleted = entity.Deleted;

                primitive.Deactivated = entity.Deactivated;

                primitive.Number = entity.Number;

                primitive.Year = entity.Year;

                primitive.DeactivationReason = entity.DeactivationReason;

                return primitive;
        }
Ejemplo n.º 4
0
        public static DeliveryNotePrimitive GetPrimitiveCopy(this DeliveryNotePrimitive primitiveToCopy)
        {
            if (primitiveToCopy == null) return null;

                DeliveryNotePrimitive primitive = new DeliveryNotePrimitive();

                primitive.Id = primitiveToCopy.Id;

                primitive.Driver_Id = primitiveToCopy.Driver_Id;

                primitive.DateDrawing = primitiveToCopy.DateDrawing;

                primitive.DateOfArrival = primitiveToCopy.DateOfArrival;

                primitive.Drawer = primitiveToCopy.Drawer;

                primitive.Car_Id = primitiveToCopy.Car_Id;

                primitive.Amount = primitiveToCopy.Amount;

                primitive.Order_Id = primitiveToCopy.Order_Id;

                primitive.Deleted = primitiveToCopy.Deleted;

                primitive.Deactivated = primitiveToCopy.Deactivated;

                primitive.Number = primitiveToCopy.Number;

                primitive.Year = primitiveToCopy.Year;

                primitive.DeactivationReason = primitiveToCopy.DeactivationReason;

                return primitive;
        }