private Response CreateDelivery(dynamic args)
        {
            int?           lifetime    = args.lifetime;
            DeliveryObject newDelivery = _repository.Create(args.title, _systemClock.Now, lifetime.HasValue ? TimeSpan.FromSeconds(lifetime.Value) : TimeSpan.FromDays(1));

            return(Response.AsJson(newDelivery)
                   .WithContentType("application/json")
                   .WithStatusCode(HttpStatusCode.Created));
        }
Ejemplo n.º 2
0
        public AmazonSESDeliveryNotification(string notification)
        {
            AmazonSESNotification amazonSESNotification = null;

            if (TryParse(notification, out amazonSESNotification))
            {
                var amazonSESDeliveryNotification = amazonSESNotification as AmazonSESDeliveryNotification;
                Mail             = amazonSESDeliveryNotification.Mail;
                NotificationType = amazonSESDeliveryNotification.NotificationType;
                Delivery         = amazonSESDeliveryNotification.Delivery;
            }
        }
Ejemplo n.º 3
0
        public DeliveryObject Create(string title, DateTime time, TimeSpan lifetime)
        {
            var newDelivery = new DeliveryObject
            {
                Title        = title,
                PersonId     = -1,
                Status       = DeliveryStatus.Available,
                CreationTime = time,
                Lifetime     = lifetime
            };

            _context.Deliveries.Add(newDelivery);
            return(newDelivery);
        }
Ejemplo n.º 4
0
        private void btn_del_calccost_Click(object sender, EventArgs e)
        {
            if (txtb_del_distance.Text == "" || txtb_del_rate.Text == "")
            {
                MessageBox.Show("Fill Distance and Rate");
            }
            DeliveryObject delobj = new DeliveryObject();

            delobj.Distance1 = Convert.ToDouble(txtb_del_distance.Text);
            delobj.Rate1     = Convert.ToDouble(txtb_del_rate.Text);

            MegaCoolMethods mcm  = new MegaCoolMethods();
            double          cost = mcm.calcCost(delobj);

            delobj.Cost1       = cost;
            txtb_del_cost.Text = cost.ToString();
        }
        private Response TakeDelivery(dynamic args)
        {
            var user = _userRepository.GetPerson(args.user);

            if (user == null)
            {
                return(Response.AsError(HttpStatusCode.Unauthorized, "Can`t find user"));
            }

            DeliveryObject myDelivery = _repository.GetDelivery(args.delivery);

            if (myDelivery == null)
            {
                return(Response.AsError(HttpStatusCode.NotFound, "Can`t find delivery"));
            }
            if (myDelivery.Status != DeliveryStatus.Available)
            {
                return(Response.AsError(HttpStatusCode.UnprocessableEntity, "Wrong status! Delivery must have status Available"));
            }
            if (myDelivery.CreationTime + myDelivery.Lifetime < _systemClock.Now)
            {
                myDelivery.Lifetime = TimeSpan.Zero;
                myDelivery.Status   = DeliveryStatus.Expired;
                _repository.UpdateDelivery(myDelivery);
                return(Response.AsError(HttpStatusCode.BadRequest, "Error! Delivery expired!"));
            }

            myDelivery.Lifetime = TimeSpan.Zero;
            myDelivery.Status   = DeliveryStatus.Taken;
            myDelivery.PersonId = user.Id;

            _repository.UpdateDelivery(myDelivery);

            return(Response.AsJson(myDelivery)
                   .WithContentType("application/json")
                   .WithStatusCode(HttpStatusCode.Accepted));
        }
Ejemplo n.º 6
0
        private void btn_del_update_Click(object sender, EventArgs e)
        {
            DeliveryObject objdel  = new DeliveryObject();
            CustomerObject objcus  = new CustomerObject();
            SalesObject    objInv  = new SalesObject();
            EmployeeObject objemp  = new EmployeeObject();
            VehicalObject  objvehi = new VehicalObject();



            //chechk whether text feilds are empty or not
            if (txtb_del_deliveryno.Text == "" || txtb_del_invoiceid.Text == "" || txtb_del_cusid.Text == "" || txtb_del_driver.Text == "" || txtb_del_vehicalno.Text == "" || comb_del_status.Text == "" || rtxtb_del_description.Text == "" || txtb_del_from.Text == "" || txtb_del_to.Text == "" || txtb_del_distance.Text == "" || txtb_del_rate.Text == "" || txtb_del_cost.Text == "")
            {
                MessageBox.Show("Please fill the all required feilds");
            }
            else
            {
                // objdel.DeliveryNo1 = txtb_del_deliveryno.Text;
                //  objInv.InvoiceID1 = Convert.ToInt32(txtb_del_invoiceid.Text);
                //  objcus.Nic = txtb_del_cusid.Text;
                objemp.empid        = Convert.ToInt32(txtb_del_driver.Text);
                objvehi.VehicalNo   = txtb_del_vehicalno.Text;
                objdel.Status1      = comb_del_status.Text;
                objdel.Description1 = rtxtb_del_description.Text;
                objdel.From1        = txtb_del_from.Text;
                objdel.To1          = txtb_del_to.Text;
                objdel.Distance1    = Convert.ToDouble(txtb_del_distance.Text);
                objdel.Rate1        = Convert.ToDouble(txtb_del_rate.Text);
                objdel.Cost1        = Convert.ToDouble(txtb_del_cost.Text);
                objdel.Date         = dtp_del_delDate.Value.Date;

                //show the confirmation dialog box
                DialogResult dr;
                dr = MessageBox.Show("Do you want to save the record", "Confirm", MessageBoxButtons.YesNo);
                string Dr = dr.ToString();

                if (Dr == "Yes")
                {
                    try
                    {
                        MegaCoolMethods mcm    = new MegaCoolMethods();
                        bool            result = mcm.AddNewdelivery(objdel, objcus, objInv, objemp, objvehi);


                        if (result)
                        {
                            MessageBox.Show("Successfully Saved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            // FillMemberDetails();
                        }
                        else
                        {
                            MessageBox.Show("Unable to Save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (ApplicationException appEx)
                    {
                        MessageBox.Show(appEx.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    catch (SqlException ex)
                    {
                        if (ex.Number == 2627)
                        {
                            MessageBox.Show("This Delivery Number is already Exsists");
                        }
                    }

                    rbtn_del_delivery.Checked = true;
                    deliveryDELIVERYFillGrid();
                    deliveryProcessingDELIVERYFillGrid();
                    //else
                    //    MessageBox.Show("Data is not entered");

                    //deliveryFillGrid();
                    //vehi_clear();
                }
                //}
            }
        }
Ejemplo n.º 7
0
        public async void TestTakeDelivery()
        {
            var dateTime = new DateTime(1999, 01, 01);

            // Arrange
            var deliveryObject = new DeliveryObject {
                Id = 101, Title = "Box of Shugar", Status = DeliveryStatus.Available, Lifetime = TimeSpan.MaxValue
            };
            var deliveryObject2 = new DeliveryObject {
                Id = 102, Title = "Box of Tea", Status = DeliveryStatus.Taken, Lifetime = TimeSpan.MaxValue
            };
            var deliveryObject3 = new DeliveryObject {
                Id = 103, Title = "Box of Coffee", Status = DeliveryStatus.Available, Lifetime = TimeSpan.Zero, CreationTime = dateTime + TimeSpan.FromSeconds(1)
            };
            var deliveryMock = new Mock <IDeliveryRepository>();

            deliveryMock.Setup(r => r.GetDelivery(It.Is <int>(i => i == 101))).Returns(deliveryObject);
            deliveryMock.Setup(r => r.GetDelivery(It.Is <int>(i => i == 102))).Returns(deliveryObject2);
            deliveryMock.Setup(r => r.GetDelivery(It.Is <int>(i => i == 103))).Returns(deliveryObject3);
            deliveryMock.Setup(r => r.UpdateDelivery(It.IsAny <DeliveryObject>()));

            var date = new Mock <IDateTime>();

            date.Setup(repo => repo.Now).Returns(dateTime);

            var user = new Person {
                Id = 42, Name = "Max Plank"
            };
            var userMock = new Mock <IUserRepository>();

            userMock.Setup(u => u.GetPerson(It.Is <int>(i => i == 42))).Returns(user);

            // Init module
            var module  = new DeliveryModule(date.Object, deliveryMock.Object, userMock.Object);
            var browser = new Browser(b => b.Module(module));

            // Act
            var resultNotUser = await browser.Post($"/delivery/take/41.101");

            var resultNotDelivery = await browser.Post($"/delivery/take/42.100");

            var resultWrongStatus = await browser.Post($"/delivery/take/42.102");

            var resultBadRequest = await browser.Post($"/delivery/take/42.103");

            var resultOk = await browser.Post($"/delivery/take/42.101");

            // Assert
            Assert.Equal(resultNotUser.StatusCode, HttpStatusCode.Unauthorized);
            Assert.Equal(resultNotDelivery.StatusCode, HttpStatusCode.NotFound);
            Assert.Equal(resultWrongStatus.StatusCode, HttpStatusCode.UnprocessableEntity);
            Assert.Equal(resultBadRequest.StatusCode, HttpStatusCode.BadRequest);

            Assert.Equal(resultOk.StatusCode, HttpStatusCode.Accepted);
            deliveryMock.Verify(dr => dr.UpdateDelivery(It.Is(
                                                            (DeliveryObject o) =>
                                                            o.Id == deliveryObject.Id &&
                                                            o.Lifetime == TimeSpan.Zero &&
                                                            o.Status == DeliveryStatus.Taken &&
                                                            o.PersonId == user.Id)), Times.Once());
        }
Ejemplo n.º 8
0
 public async void UpdateDelivery(DeliveryObject delivery)
 {
     _context.Deliveries.Update(delivery);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 9
0
 public bool Add(DeliveryObject delivery)
 {
     _context.Deliveries.Add(delivery);
     _context.SaveChanges();
     return(true);
 }