示例#1
0
        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                pnlErrorMessage.Visible = true;
                litErrorMessage.Text    = "There are errors";
                return;
            }

            DistributionCentre centre = new DistributionCentre()
            {
                CentreId = int.Parse(ddlLocation.SelectedValue)
            };

            EmployeeType employeeType = (EmployeeType)Enum.Parse(typeof(EmployeeType), rblEmployeeType.SelectedValue);

            Result result = _employeeService.Update(litUserName.Text, txtFullName.Text, txtEmailAddress.Text, centre, employeeType);

            if (result.Success)
            {
                pnlMessage.Visible = true;
                litMessage.Text    = "Successfully saved";
            }
            else
            {
                var err = new CustomValidator();
                err.ValidationGroup = "userDetails";
                err.IsValid         = false;
                err.ErrorMessage    = result.ErrorMessage;
                Page.Validators.Add(err);

                pnlErrorMessage.Visible = true;
                litErrorMessage.Text    = "There are errors";
            }
        }
示例#2
0
        /// <summary>
        /// Attempts to update package with "packageId" to discard it, if currently logged employee is autorized
        /// Sets package's status as discarded
        /// </summary>
        /// <param name="barCode"></param>
        /// <param name="distributionCentre"></param>
        /// <param name="employee"></param>
        /// <param name="expirationDate"></param>
        /// <param name="packageType"></param>
        /// <param name="packageId"></param>
        /// <returns> Result object according to success or failure </returns>
        public Result Discard(string barCode, DistributionCentre distributionCentre, Employee employee, DateTime expirationDate, StandardPackageType packageType, int packageId)
        {
            var result = new Result
            {
                Success = true
            };

            if (employee.EmployeeType == EmployeeType.Manager)
            {
                result.Success      = false;
                result.ErrorMessage = PackageResult.EmployeeNotAuthorized;
                return(result);
            }

            Package package = new Package
            {
                PackageType     = packageType,
                CurrentLocation = distributionCentre,
                CurrentStatus   = PackageStatus.Discarded,
                PackageId       = packageId,
                ExpirationDate  = expirationDate,
                DistributedBy   = null,
                BarCode         = barCode
            };

            _packageRepository.Update(package);

            result.Id = package.PackageId;

            return(result);
        }
示例#3
0
        /// <summary>
        /// Registers and Creates new Packages of a Standard Packahe Type for a given location and
        /// has the specified expiration date. The Barcode is generated from the Package Type Id, Expiration Date and Package Id
        /// </summary>
        /// <param name="packageType"></param>
        /// <param name="location"></param>
        /// <param name="expirationDate"></param>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public Result Register(StandardPackageType packageType, DistributionCentre location, DateTime expirationDate, out string barcode)
        {
            var result = new Result
            {
                Success = true
            };

            barcode = string.Empty;

            if (expirationDate < DateTime.Today)
            {
                result.Success      = false;
                result.ErrorMessage = PackageResult.ExpirationDateCannotBeEarlierThanToday;
                return(result);
            }

            Package package = new Package
            {
                PackageType     = packageType,
                CurrentLocation = location,
                CurrentStatus   = PackageStatus.InStock,
                ExpirationDate  = expirationDate
            };

            int packageId = _packageRepository.Insert(package);

            package.PackageId = packageId;
            barcode           = GenerateBarCode(package);
            package.BarCode   = barcode;
            _packageRepository.Update(package);
            result.Id = package.PackageId;
            return(result);
        }
示例#4
0
        /// <summary>
        /// Repository for Reconciled Package screen in Package Audit Wizard
        /// </summary>
        /// <param name="currentLocation"></param>
        /// <param name="packageType"></param>
        /// <param name="barCodeList"></param>
        /// <returns></returns>
        public List <ReconciledPackage> GetReconciledPackages(DistributionCentre currentLocation, StandardPackageType packageType, List <string> barCodeList)
        {
            List <ReconciledPackage> packageList = null;

            packageList = ViewDataAccess.GetReconciledPackages(_connectionString, currentLocation, packageType, barCodeList);
            return(packageList);
        }
示例#5
0
        public ActionResult Register(PackageRegisterViewModel model)
        {
            var packageService  = GetPackageService();
            var employeeService = GetEmployeeService();

            if (ModelState.IsValid)
            {
                int packageId = 1;

                StandardPackageType selectedPackageType = packageService.GetStandardPackageType(model.StandardPackageTypeId);
                DistributionCentre  selectedCentre      = employeeService.GetDistributionCentre(model.LocationCentreId);
                string barCode;

                Result result = packageService.Register(selectedPackageType, selectedCentre, model.ExpirationDate, out barCode);
                if (result.Success)
                {
                    model.BarCode = barCode;
                    return(View("RegisterComplete", model));
                }
                else
                {
                    ModelState.AddModelError("", result.ErrorMessage);
                }
            }

            model.DistributionCentres  = employeeService.GetAllDistributionCentres();
            model.StandardPackageTypes = packageService.GetAllStandardPackageTypes();

            return(View("Register", model));
        }
示例#6
0
        public ActionResult ReceiveSave(PackageTransitReceiveViewModel model)
        {
            var packageService  = GetPackageService();
            var employeeService = GetEmployeeService();
            var employee        = GetCurrentEmployee();

            DistributionCentre locationCentre = employeeService.GetDistributionCentre(employee.LocationCentreId);

            if (ModelState.IsValid && model.SelectedPackages != null && model.SelectedPackages.Any())
            {
                foreach (var package in model.SelectedPackages)
                {
                    Result result = packageService.Receive(package.BarCode, locationCentre, model.ReceiveDate);
                    if (result.Success)
                    {
                        package.ProcessResultMessage = "Successful!";
                    }
                    else
                    {
                        package.ProcessResultMessage = result.ErrorMessage;
                    }
                }

                return(View("ReceiveComplete", model));
            }
            else
            {
                if (model.SelectedPackages == null || !model.SelectedPackages.Any())
                {
                    model.SelectedPackages = new List <SelectedPackage>();
                    ModelState.AddModelError("", PackageResult.NoBarCodesSelected);
                }
                return(View("Receive", model));
            }
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            IPackageRepository packageRepository = new PackageRepository(ConfigurationManager.ConnectionStrings["ENetCare"].ConnectionString);

            _packageService = new PackageService(packageRepository);

            IEmployeeRepository repository = new EmployeeRepository(ConfigurationManager.ConnectionStrings["ENetCare"].ConnectionString);

            _employeeService = new EmployeeService(repository);

            ucPackageBarcode.AddValidate += PackageBarcodeOnAdd;

            if (!Page.IsPostBack)
            {
                var centres = _employeeService.GetAllDistributionCentres();

                ddlDestination.DataTextField  = "Name";
                ddlDestination.DataValueField = "CentreId";
                ddlDestination.DataSource     = centres;
                ddlDestination.DataBind();

                SetSendDateTextBox(DateTime.Today);

                EmployeeMembershipUser user          = (EmployeeMembershipUser)System.Web.Security.Membership.GetUser();
                DistributionCentre     _senderCentre = _employeeService.GetDistributionCentre(user.DistributionCentreId);
                ViewState["senderCentre"] = _senderCentre;
            }
            else if (!string.IsNullOrEmpty(Request.Form[txtSendDate.UniqueID]))
            {
                DateTime sendDate = DateTime.Parse(Request.Form[txtSendDate.UniqueID]);
                SetSendDateTextBox(sendDate);
            }
        }
示例#8
0
 public ActionResult EditCentreConfirmed(DistributionCentre centre)
 {
     db.Entry(centre).State = EntityState.Modified;
     db.SaveChanges();
     TempData["alertMessage"] = "Пункт выдачи успешно изменен.";
     return(RedirectToAction("CentresSettings"));
 }
示例#9
0
        public DistributionCentre GetDistributionCentre(int centreid)
        {
            DistributionCentre centre = null;

            centre = DataAccess.GetDistributionCentre(_connectionString, centreid);
            return(centre);
        }
示例#10
0
        public ActionResult EditCentre([Bind(Include = "Id,Index,CityId,Address,Description")] DistributionCentre centre)
        {
            if (ModelState.IsValid)
            {
                if (db.DistributionCentres.Where(a => a.CityId == centre.CityId && a.Address == centre.Address && a.Id != centre.Id).Count() == 0)
                {
                    string temp = "/" + centre.Id.ToString().Length + "/" + centre.Index.Length + "/" + centre.CityId.ToString().Length + "/" + centre.Address.Length + "/" + centre.Description.Length + "/";
                    temp += centre.Id.ToString();
                    temp += centre.Index;
                    temp += centre.CityId.ToString();
                    temp += centre.Address;
                    temp += centre.Description;
                    return(RedirectToAction("Confirm", new { act = "EditUser", obj = temp }));
                }
                else
                {
                    ModelState.AddModelError("", "Такой пункт выдачи уже существует");
                }
            }
            List <IdValueModel> cities = new List <IdValueModel>();

            cities.Add(new IdValueModel {
                Id = null, Value = "(Не выбран)"
            });
            foreach (City p in db.Cities)
            {
                string str1 = p.NameCity + ", " + p.Region.NameRegion + ", " + p.Region.Country.NameCountry;
                cities.Add(new IdValueModel {
                    Id = p.Id, Value = str1
                });
            }
            ViewBag.CityId = new SelectList(cities, "Id", "Value", null);
            return(View(centre));
        }
示例#11
0
        public ActionResult EditCentre(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DistributionCentre centre = db.DistributionCentres.Find(id);

            if (centre == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            List <IdValueModel> cities = new List <IdValueModel>();

            cities.Add(new IdValueModel {
                Id = null, Value = "(Не выбран)"
            });
            foreach (City p in db.Cities)
            {
                string str1 = p.NameCity + ", " + p.Region.NameRegion + ", " + p.Region.Country.NameCountry;
                cities.Add(new IdValueModel {
                    Id = p.Id, Value = str1
                });
            }
            ViewBag.CityId = new SelectList(cities, "Id", "Value", null);
            return(View(centre));
        }
示例#12
0
 public ActionResult CreateCentreConfirmed(DistributionCentre centre)
 {
     db.DistributionCentres.Add(centre);
     db.SaveChanges();
     TempData["alertMessage"] = "Пункт выдачи успешно создан.";
     return(RedirectToAction("CentresSettings"));
 }
示例#13
0
        public static List <DistributionCentre> GetAllDistributionCentres(SqlConnection connection)
        {
            var    centres = new List <DistributionCentre>();
            string query   = "SELECT CentreId, Name, Address, Phone, IsHeadOffice FROM DistributionCentre ORDER BY CentreId";

            var cmd = new SqlCommand(query);

            cmd.Connection = connection;

            using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
            {
                while (reader.Read())
                {
                    var centre = new DistributionCentre();

                    centre.CentreId     = Convert.ToInt32(reader["CentreId"]);
                    centre.Name         = (string)reader["Name"];
                    centre.Address      = (string)reader["Address"];
                    centre.Phone        = (string)reader["Phone"];
                    centre.IsHeadOffice = (bool)reader["IsHeadOffice"];

                    centres.Add(centre);
                }
            }

            return(centres);
        }
示例#14
0
        public static DistributionCentre GetDistributionCentre(SqlConnection connection, int centreId)
        {
            DistributionCentre centre = null;
            string             query  = "SELECT CentreId, Name, Address, Phone, IsHeadOffice FROM DistributionCentre WHERE CentreId = @centreId";

            var cmd = new SqlCommand(query);

            cmd.Connection = connection;

            cmd.Parameters.AddWithValue("@centreId", centreId);

            using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
            {
                if (reader.Read())
                {
                    centre = new DistributionCentre();

                    centre.CentreId     = Convert.ToInt32(reader["CentreId"]);
                    centre.Name         = (string)reader["Name"];
                    centre.Address      = (string)reader["Address"];
                    centre.Phone        = (string)reader["Phone"];
                    centre.IsHeadOffice = (bool)reader["IsHeadOffice"];
                }
            }

            return(centre);
        }
示例#15
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            string   connectionString = ConfigurationManager.ConnectionStrings["ENetCareLiveAll"].ConnectionString;
            Entities context          = new Entities(connectionString);

            if (ModelState.IsValid)
            {
                DistributionCentre locationCentre =
                    context.DistributionCentre.FirstOrDefault(d => d.CentreId == model.LocationCentreId);
                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email    = model.Email,
                    Fullname = model.FullName,
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    result = await UserManager.AddToRoleAsync(user.Id, model.EmployeeType.ToString());
                }

                int written = 0;
                if (result.Succeeded)
                {
                    Employee employee = new Employee();
                    employee.UserId           = new Guid(user.Id);
                    employee.UserName         = user.UserName;
                    employee.FullName         = model.FullName;
                    employee.LocationCentreId = model.LocationCentreId;
                    employee.EmployeeType     = model.EmployeeType;
                    employee.EmailAddress     = model.Email;

                    context.Employee.Add(employee);
                    written = context.SaveChanges();
                }

                if (result.Succeeded && written > 0)
                {
                    await SignInAsync(user, isPersistent : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                else if (!result.Succeeded)
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            model.DistributionCentres = context.DistributionCentre;
            return(View(model));
        }
示例#16
0
        public ActionResult Category6()
        {
            DistributionCentre   centre           = db.Users.FirstOrDefault(a => a.Login == User.Identity.Name).AccountReferences.FirstOrDefault()?.DistributionCentre;
            List <Package>       suitablePackages = GetSuitablePackages(Statuses[4], centre);
            PackageListViewModel list             = new PackageListViewModel(suitablePackages, "В пункте выдачи", centre);

            return(View("Index", list));
        }
示例#17
0
        public static int InsertDistributionCentre(DistributionCentre d)
        {
            int newId = mockDistributionCentreDb.Count();

            d.CentreId = newId;
            mockDistributionCentreDb[newId] = d;
            return(newId);
        }
示例#18
0
        public ActionResult Category10()
        {
            DistributionCentre   centre           = db.Users.FirstOrDefault(a => a.Login == User.Identity.Name).AccountReferences.FirstOrDefault()?.DistributionCentre;
            List <Package>       suitablePackages = GetSuitablePackages(null, centre);
            PackageListViewModel list             = new PackageListViewModel(suitablePackages, "Без статуса", centre);

            return(View("Index", list));
        }
示例#19
0
        public ActionResult DeleteCentreConfirmed(int id)
        {
            DistributionCentre centre = db.DistributionCentres.Find(id);

            db.DistributionCentres.Remove(centre);
            db.SaveChanges();
            TempData["alertMessage"] = "Пункт выдачи успешно удален.";
            return(RedirectToAction("CentresSettings"));
        }
示例#20
0
        public int UpdateInstockFromAudit(int auditId, DistributionCentre location, StandardPackageType packageType)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                return(DataAccess.UpdateInstockFromAudit(connection, auditId, location, packageType));
            }
        }
示例#21
0
        public int UpdateTransitCancelledFromAudit(int auditId, DistributionCentre location)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                return(DataAccess.UpdateTransitCancelledFromAudit(connection, auditId, location));
            }
        }
示例#22
0
        /// <summary>
        /// Attempts to update package with "barCode" and its associated transit
        /// sets packages location and status
        /// sets transit's "date received" as today
        /// </summary>
        /// <param name="barCode"></param>
        /// <param name="receiverCentre"></param>
        /// <param name="date"></param>
        /// <returns> Result object according to success or failure </returns>
        public Result Receive(string barCode, DistributionCentre receiverCentre, DateTime receiveDate)
        {                                                                 // (P. 24-03-2015)
            Result  receiveResult = new Result();
            Package package       = _packageRepository.GetPackageWidthBarCode(barCode);

            if (package == null)                         // Case: not found
            {
                receiveResult.ErrorMessage = TransitResult.BarCodeNotFound;
                receiveResult.Success      = false;
                return(receiveResult);
            }
            if (package.CurrentLocation != null && package.CurrentLocation.CentreId == receiverCentre.CentreId)
            {
                receiveResult.Success      = false;
                receiveResult.ErrorMessage = TransitResult.PackageAlreadyAtDestination;
                return(receiveResult);
            }

            PackageTransit activeTransit = _packageRepository.GetTransit(package, receiverCentre);

            if (activeTransit == null)
            {
                // Maybe the open transit has a different destination
                activeTransit = _packageRepository.GetOpenTransit(package);
            }

            // If there is an active transit set Date Received or Date Cancelled and update
            // Even if there is no transit record the receive should still work
            if (activeTransit != null)
            {
                if (receiveDate < activeTransit.DateSent)
                {
                    receiveResult.Success      = false;
                    receiveResult.ErrorMessage = PackageResult.ReceiveDateCannotBeEarlierThanSend;
                    return(receiveResult);
                }

                if (activeTransit.ReceiverCentreId == receiverCentre.CentreId)
                {
                    activeTransit.DateReceived = receiveDate;
                }
                else
                {
                    activeTransit.DateCancelled = receiveDate; // something went wrong with the transit so just cancel it
                }
                _packageRepository.UpdateTransit(activeTransit);
            }

            package.CurrentStatus           = PackageStatus.InStock;   // set packagestatus
            package.CurrentLocationCentreId = receiverCentre.CentreId; // set package location
            package.DistributedByEmployeeId = null;                    // set distributed by employee to null
            _packageRepository.Update(package);                        // update packages DB
            receiveResult.Success = true;
            receiveResult.Id      = package.PackageId;
            return(receiveResult);
        }
示例#23
0
        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                pnlErrorMessage.Visible = true;
                litErrorMessage.Text    = "There are errors";
                return;
            }

            int selectedPackageTypeId = int.Parse(ddlPackageType.SelectedValue);

            StandardPackageType selectedPackageType = _packageService.GetStandardPackageType(selectedPackageTypeId);

            int selectedCentreId = int.Parse(ddlLocation.SelectedValue);

            DistributionCentre selectedCentre = _employeeService.GetDistributionCentre(selectedCentreId);

            DateTime expirationDate = DateTime.Parse(Request.Form[txtExpirationDate.UniqueID]);

            SetExpirationDateTextBox(expirationDate);

            string barcode;

            Result result = _packageService.Register(selectedPackageType, selectedCentre, expirationDate, out barcode);

            if (!result.Success)
            {
                var err = new CustomValidator();
                err.ValidationGroup = "userDetails";
                err.IsValid         = false;
                err.ErrorMessage    = result.ErrorMessage;
                Page.Validators.Add(err);

                pnlErrorMessage.Visible = true;
                litErrorMessage.Text    = "There are errors";
                return;
            }

            pnlMessage.Visible = true;
            litMessage.Text    = "Successfully saved";

            litBarcode.Text = barcode;

            string strImageURL = "~/Handler/GenerateBarcodeImage.ashx?d=" + barcode;

            this.ImageBarcode.ImageUrl = strImageURL;
            this.ImageBarcode.Width    = 400;
            this.ImageBarcode.Height   = 150;
            this.ImageBarcode.Visible  = true;

            ddlPackageType.Enabled    = false;
            txtExpirationDate.Enabled = false;
            ddlLocation.Enabled       = false;
            btnSave.Enabled           = false;
            btnNext.Enabled           = true;
        }
示例#24
0
        private Result SendPackage(int packageId, int senderCenterId, int receiverCenterId)
        {
            IPackageRepository _mockPackageRepository = new MockPackageRepository();
            PackageService     _packageServices       = new PackageService(_mockPackageRepository);
            Package            _package             = MockDataAccess.GetPackage(packageId);
            DistributionCentre _senderLocation      = MockDataAccess.GetDistributionCentre(senderCenterId);
            DistributionCentre _destinationLocation = MockDataAccess.GetDistributionCentre(receiverCenterId);

            return(_packageServices.Send(_package, _senderLocation, _destinationLocation, DateTime.Today));
        }
示例#25
0
        public static int AddDistributionCentre(string Name, string Address, string Phone, bool IsHeadOffice)
        {
            DistributionCentre newCentre = new DistributionCentre();

            newCentre.Address      = Address;
            newCentre.Name         = Name;
            newCentre.IsHeadOffice = IsHeadOffice;
            newCentre.Phone        = Phone;
            return(InsertDistributionCentre(newCentre));
        }
示例#26
0
        public static int AddPackage(StandardPackageType Type, string BarCode, DistributionCentre Location, PackageStatus Status, DateTime Expiration)
        {
            Package newPackage = new Package();

            newPackage.BarCode         = BarCode;
            newPackage.CurrentLocation = Location;
            newPackage.CurrentStatus   = Status;
            newPackage.ExpirationDate  = Expiration;
            newPackage.PackageType     = Type;
            return(InsertPackage(newPackage));
        }
示例#27
0
        public ActionResult Category8()
        {
            DistributionCentre centre           = db.Users.FirstOrDefault(a => a.Login == User.Identity.Name).AccountReferences.FirstOrDefault()?.DistributionCentre;
            List <Package>     suitablePackages = GetSuitablePackages(Statuses[7], centre);

            suitablePackages.AddRange(GetSuitablePackages(Statuses[8], centre));
            suitablePackages.AddRange(GetSuitablePackages(Statuses[9], centre));
            PackageListViewModel list = new PackageListViewModel(suitablePackages, "Возвраты", centre);

            return(View("Index", list));
        }
示例#28
0
        // Try to send Package into the Sender Centre location
        public void TestSendPackage_SameLocation()
        {
            IPackageRepository _mockPackageRepository = new MockPackageRepository();
            PackageService     _packageServices       = new PackageService(_mockPackageRepository);
            Package            _package        = MockDataAccess.GetPackage(3);
            DistributionCentre _senderLocation = MockDataAccess.GetDistributionCentre(2);
            DateTime           _sendDate       = DateTime.Today;
            var _result = _packageServices.Send(_package, _senderLocation, _senderLocation, _sendDate);

            Assert.AreEqual <bool>(false, _result.Success);
        }
示例#29
0
        public void TestReceivePackage_BarcodeNotFound()
        {
            MockPackageRepository myMockPackageRepo = new MockPackageRepository();
            PackageService        packageService    = new PackageService(myMockPackageRepo);
            DistributionCentre    myReceiverCentre  = MockDataAccess.GetDistributionCentre(3);
            string bCode = "0001015042500004";        // package1.BarCode; //
            Result res   = packageService.Receive(bCode, myReceiverCentre, DateTime.Today);

            Assert.AreEqual <bool>(res.Success, false);
            Assert.AreEqual <string>(res.ErrorMessage, TransitResult.BarCodeNotFound);
        }
示例#30
0
        public static List <Package> GetAllPackages(string connectionString, DistributionCentre location = null)
        {
            List <Package> packages = null;

            using (var ctx = new Entities(connectionString))
            {
                packages = ctx.Package.Where(p => (location == null ? p.CurrentLocationCentreId : location.CentreId) == p.CurrentLocationCentreId).ToList();
            }

            return(packages);
        }