Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(int?id)
        {
            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                var entity = await db.Penalties.FindAsync(id);

                if (entity == null)
                {
                    return(HttpNotFound());
                }

                var model = new PenaltyModel
                {
                    PayRate    = entity.PayRate,
                    From       = entity.From,
                    To         = entity.To,
                    PenaltyFee = entity.PenaltyFee,
                };

                return(View(model));
            }
            catch (Exception e)
            {
                AddAlert($"Oops! something went wrong. Error code: {e.HResult}", "Edit", this.GetType().ToString(), AlertType.error, e);
                return(View(new ProjectModel()));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create(PenaltyModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entity = new Penalty
                    {
                        PayRate      = model.PayRate,
                        From         = model.From,
                        To           = model.To,
                        PenaltyFee   = model.PenaltyFee,
                        LastUpdate   = DateTime.Now,
                        CreationDate = DateTime.Now,
                        IsDeleted    = false,
                    };

                    db.Penalties.Add(entity);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                AddAlert($"Oops! something went wrong. Error code: {e.HResult}", "Create(model)", this.GetType().ToString(), AlertType.error, e);
            }

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Edit(PenaltyModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entity = await db.Penalties.FindAsync(model.Id);

                    if (entity == null)
                    {
                        return(HttpNotFound());
                    }

                    entity.PayRate    = model.PayRate;
                    entity.From       = model.From;
                    entity.To         = model.To;
                    entity.PenaltyFee = model.PenaltyFee;
                    entity.LastUpdate = DateTime.Now;

                    db.Entry(entity).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
            catch (Exception e)
            {
                AddAlert($"Oops! something went wrong. Error code: {e.HResult}", "Edit(model)", this.GetType().ToString(), AlertType.error, e);
                return(View(model));
            }
        }
Ejemplo n.º 4
0
        private IList <PenaltyModel> ProcessPenaltySheetPlayer(ExcelRange penalties, int rowOffset, bool isFirstHalf)
        {
            List <PenaltyModel> list = new List <PenaltyModel>();
            int columnOffset         = 2;

            while (columnOffset < 10)
            {
                // go through each foul
                object foulTypeObj = penalties.SubRange(rowOffset, columnOffset).Value;
                if (foulTypeObj == null || string.IsNullOrWhiteSpace(foulTypeObj.ToString()))
                {
                    columnOffset++;
                    continue;
                }
                string foulType   = foulTypeObj.ToString().Trim();
                char?  specialKey = null;
                if (foulType.Length > 1)
                {
                    specialKey = foulType[1];
                    foulType   = foulType.Substring(0, 1);
                }
                int          jamNumber = Convert.ToInt32(penalties.SubRange(rowOffset + 1, columnOffset).Value);
                PenaltyModel penalty   = new PenaltyModel
                {
                    IsFirstHalf = isFirstHalf,
                    JamNumber   = jamNumber,
                    PenaltyCode = foulType,
                    SpecificKey = specialKey
                };
                list.Add(penalty);
                columnOffset++;
            }
            return(list);
        }
Ejemplo n.º 5
0
        public ActionResult Index()
        {
            var data  = _penaltyBLL.GetPenalty();
            var model = new PenaltyModel();

            model.Details = Mapper.Map <List <PenaltyItem> >(data);
            foreach (var item in model.Details)
            {
                var Vendor = _vendorBLL.GetByID(item.Vendor);
                if (Vendor != null)
                {
                    item.VendorName = Vendor.VendorName;
                }
            }
            model.MainMenu          = _mainMenu;
            model.CurrentLogin      = CurrentUser;
            model.CurrentPageAccess = CurrentPageAccess;
            if (CurrentUser.UserRole == Enums.UserRole.Viewer)
            {
                model.IsShowNewButton = false;
                model.IsNotViewer     = false;
            }
            else
            {
                model.IsShowNewButton = true;
                model.IsNotViewer     = true;
            }
            return(View(model));
        }
Ejemplo n.º 6
0
 public HttpResponseMessage Save(PenaltyModel model)
 {
     try
     {
         if (this.ModelState.IsValid)
         {
             var PenaltyList = service.SavePenalty(model);
             if (PenaltyList != null)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, PenaltyList));
             }
             else
             {
                 string message = "Error Saving Data";
                 return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message));
             }
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message));
     }
 }
Ejemplo n.º 7
0
        public ActionResult Upload()
        {
            var model = new PenaltyModel();

            model.MainMenu     = _mainMenu;
            model.CurrentLogin = CurrentUser;
            return(View(model));
        }
 public async Task AddPenalty(PenaltyModel model)
 {
     using (HttpResponseMessage response = await _apiHelper.ApiClient.PostAsJsonAsync("/api/penalty/AddPenalty", model))
     {
         if (response.IsSuccessStatusCode == false)
         {
             throw new Exception(response.ReasonPhrase);
         }
     }
 }
        public async Task <PenaltyDto> CreateAsync(int creatorId, PenaltyDto dto)
        {
            dto.CreatorId = creatorId;
            dto.Date      = DateTime.Now;
            PenaltyModel model = _mapper.Map <PenaltyDto, PenaltyModel>(dto);
            await _unitOfWork.PenaltiesRepository.InsertAsync(model);

            await _unitOfWork.SaveAsync();

            return(dto);
        }
Ejemplo n.º 10
0
        public ActionResult Upload(PenaltyModel Model)
        {
            if (ModelState.IsValid)
            {
                foreach (PenaltyItem data in Model.Details)
                {
                    try
                    {
                        var Exist = _penaltyBLL.GetPenalty().Where(x => (x.BodyType == null ? "" : x.BodyType.ToUpper()) == (data.BodyType == null ? "" : data.BodyType.ToUpper()) &&
                                                                   (x.Manufacturer == null ? "" : x.Manufacturer.ToUpper()) == (data.Manufacturer == null ? "" : data.Manufacturer.ToUpper()) &&
                                                                   (x.Model == null ? "" : x.Model.ToUpper()) == (data.Models == null ? "" : data.Models.ToUpper()) &&
                                                                   (x.VehicleType == null ? "" : x.VehicleType.ToUpper()) == (data.VehicleType == null ? "" : data.VehicleType.ToUpper()) &&
                                                                   (x.BodyType == null ? "" : x.BodyType.ToUpper()) == (data.BodyType == null ? "" : data.BodyType.ToUpper()) &&
                                                                   (x.Series == null ? "" : x.Series.ToUpper()) == (data.Series == null ? "" : data.Series.ToUpper()) &&
                                                                   x.Year == data.Year && x.Vendor == data.Vendor && x.Penalty == data.Penalty && x.MonthEnd == data.MonthEnd && x.MonthStart == data.MonthStart && x.IsActive).FirstOrDefault();

                        if (Exist != null)
                        {
                            Exist.IsActive     = false;
                            Exist.ModifiedBy   = "SYSTEM";
                            Exist.ModifiedDate = DateTime.Now;
                            _penaltyBLL.Save(Exist);
                        }

                        data.CreatedDate  = DateTime.Now;
                        data.CreatedBy    = CurrentUser.USER_ID;;
                        data.ModifiedDate = null;
                        data.IsActive     = true;

                        var dto = Mapper.Map <PenaltyDto>(data);
                        _penaltyBLL.Save(dto);
                    }
                    catch (Exception exception)
                    {
                        Model.ErrorMessage = exception.Message;
                        Model.MainMenu     = _mainMenu;
                        Model.CurrentLogin = CurrentUser;
                        return(View(Model));
                    }
                }
                try
                {
                    _penaltyBLL.SaveChanges();
                }
                catch (Exception EXP)
                {
                    Model.ErrorMessage = EXP.Message;
                    Model.MainMenu     = _mainMenu;
                    Model.CurrentLogin = CurrentUser;
                    return(View(Model));
                }
            }
            return(RedirectToAction("Index", "MstPenalty"));
        }
Ejemplo n.º 11
0
        public async Task <PenaltyDto> DeactivateAsync(int deactivatorId, int penaltyId)
        {
            PenaltyModel model = await _unitOfWork.PenaltiesRepository.JoinAndGetAsync(penaltyId);

            _unitOfWork.PenaltiesRepository.BeginUpdate(model);
            model.DeactivatorId    = deactivatorId;
            model.Deactivated      = true;
            model.DeactivationDate = DateTime.Now;
            await _unitOfWork.SaveAsync();

            return(_mapper.Map <PenaltyModel, PenaltyDto>(model));
        }
Ejemplo n.º 12
0
        public async Task <PenaltyDto> UpdateAsync(int id, PenaltyDto dto)
        {
            dto.Account   = null;
            dto.Character = null;
            dto.Creator   = null;
            PenaltyModel model = await _unitOfWork.PenaltiesRepository.GetAsync(id);

            _mapper.Map(dto, model);
            await _unitOfWork.SaveAsync();

            return(dto);
        }
Ejemplo n.º 13
0
        public void AddPenalty(PenaltyModel model)
        {
            decimal paymentFromUI = model.Payment;

            model.Payment = _data.AmountOfPayment(model.UserId, model.BookId);

            if (paymentFromUI != model.Payment)
            {
                // Error message about diffrence in calculation UI - API
                // Get UserId
            }

            _data.AddPenalty(model);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Penalty(PenaltyModel model)
        {
            if (_signInManager.Context.User.Identity.IsAuthenticated)
            {
                if (_signInManager.Context.User.IsInRole("DepartmentHead"))
                {
                    await Initializer.InitialLayout("Department", ViewBag, _db, _signInManager, "Penalty");

                    PenaltyModel pm = new PenaltyModel
                    {
                        Employee = await _db.Employees
                                   .Where(e => e.Id == model.EmployeeId)
                                   .FirstOrDefaultAsync()
                    };
                    if (ModelState.IsValid)
                    {
                        if (pm.Employee.LastCalculate < model.GivenDate)
                        {
                            Fine fine = new Fine
                            {
                                GivenDate  = model.GivenDate,
                                Price      = model.Price,
                                EmployeeId = model.EmployeeId
                            };
                            await _db.Fines.AddAsync(fine);

                            await _db.SaveChangesAsync();
                        }
                        else
                        {
                            ModelState.AddModelError("", "You can't add penalty to this time");
                        }
                    }
                    else
                    {
                        pm.GivenDate = model.GivenDate;
                        pm.Price     = model.Price;
                    }
                    pm.Fines = await _db.Fines
                               .Where(b => b.EmployeeId == model.EmployeeId)
                               .ToListAsync();

                    return(View(pm));
                }
            }
            return(RedirectToAction("Forbidden", "Error"));
        }
Ejemplo n.º 15
0
        public IActionResult AddPenalty(PenaltyModel penaltyModel)
        {
            if (ModelState.IsValid)
            {
                Penalty penalty = new Penalty
                {
                    Date       = penaltyModel.Date,
                    EmployeeId = penaltyModel.EmployeeId,
                    Amount     = penaltyModel.Amount,
                    Reason     = penaltyModel.Reason
                };

                context.Penalties.AddAsync(penalty);
                context.SaveChangesAsync();

                return(RedirectToAction("List"));
            }

            return(View());
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Penalty(int id)
        {
            if (_signInManager.Context.User.Identity.IsAuthenticated)
            {
                if (_signInManager.Context.User.IsInRole("DepartmentHead"))
                {
                    await Initializer.InitialLayout("Department", ViewBag, _db, _signInManager, "Penalty");

                    PenaltyModel pm = new PenaltyModel
                    {
                        Fines = await _db.Fines
                                .Where(b => b.EmployeeId == id)
                                .ToListAsync(),
                        Employee = await _db.Employees
                                   .Where(e => e.Id == id)
                                   .FirstOrDefaultAsync()
                    };
                    return(View(pm));
                }
            }
            return(RedirectToAction("Forbidden", "Error"));
        }
Ejemplo n.º 17
0
        public void Kick(AccountEntity creator, string reason)
        {
            RoleplayContext ctx = Singletons.RoleplayContextFactory.Create();

            using (PenaltiesRepository repository = new PenaltiesRepository(ctx))
            {
                PenaltyModel model = new PenaltyModel()
                {
                    CreatorId   = creator?.DbModel.Id,
                    Account     = DbModel,
                    Date        = DateTime.Now,
                    PenaltyType = PenaltyType.Kick,
                    Reason      = reason
                };

                repository.Insert(model);
                repository.Save();
            }

            NAPI.Player.KickPlayer(Client, reason);
            Dispose();
        }
Ejemplo n.º 18
0
 public PenaltyViewModel(IDbService _rep, PenaltyModel _pen)
 {
     repository = _rep;
     penRef     = _pen;
     sumOpl     = penRef.Sumopl;
 }
Ejemplo n.º 19
0
 public void AddPenalty(PenaltyModel model)
 {
     _dataAccess.SaveData("spPenalty_AddPenalty", new { model.UserId, model.BookId, model.BookRentId, model.Payment }, "LibraryDatabase");
 }