// Update status Of Abonament
        // Verificam daca a expirat abonament (in functie de data)
        // Verificam daca a atins nr maxim de sedinte
        public void RefreshStatusAbonament(int abonamentID, ReportDbContext context)
        {
            AbonamentModel abonament = GetAbonamentByAbID(abonamentID, context);

            if (abonament == null)
            {
                return;
            }
            if (abonament.NrSedinteEfectuate >= abonament.TipAbonament.NrTotalSedinte)
            {
                abonament.StareAbonament = StareAbonament.Finalizat;
                context.Update(abonament);
                context.SaveChanges();
                return;
            }
            if (abonament.DataStop <= DateTime.Now)
            {
                abonament.StareAbonament = StareAbonament.Finalizat;
                context.Update(abonament);
                context.SaveChanges();
                return;
            }
            if ((abonament.DataStop - abonament.DataStart).TotalDays > 32)
            {
                abonament.StareAbonament = StareAbonament.Extins;
            }
            else
            {
                abonament.StareAbonament = StareAbonament.Activ;
            }

            context.Update(abonament);
            context.SaveChanges();
        }
Пример #2
0
        private async Task <ResultCrmDb> AddOrEditModel <TModel, TModelEdit>(TModelEdit modelDto, DbSet <TModel> models)
            where TModel : BaseModel
            where TModelEdit : IBaseModel
        {
            var result = new ResultCrmDb();

            try
            {
                var model = await models.FirstOrDefaultAsync(f => f.Id == modelDto.Id);

                model = modelDto.Map(model);
                if (model.Id == 0)
                {
                    _reportDbContext.Add(model);
                }
                else
                {
                    _reportDbContext.Update(model);
                }
                await _reportDbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result.AddError(ErrorCode.NoCode.ToString(), e.Message);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Редактировать профиль пользователя
        /// </summary>
        /// <param name="registrationUser">Данные, на которые нужно изменить профиль</param>
        /// <param name="userManager">Менеджер</param>
        /// <returns></returns>
        public async Task <ResultCrmDb> EditProfile(RegistrationUserArgs registrationUser, string userManager)
        {
            var result        = new ResultCrmDb();
            var userManagerId = userManager == null ? null : await _crmDbContext.User.Where(f => f.Account == userManager).FirstOrDefaultAsync();

            var user = await _crmDbContext.User.FirstOrDefaultAsync(f => f.Account == registrationUser.Account);

            if (user == null)
            {
                result.AddError("crm002", "Пользователя с таким аакаунтом не существует");
                result.Succeeded = false;
                return(result);
            }

            user.Email      = registrationUser.Email;
            user.Name       = registrationUser.Name;
            user.Surname    = registrationUser.Surname;
            user.Middlename = registrationUser.Middlename;
            user.Phone      = registrationUser.Phone;
            _crmDbContext.Update(user);
            await _crmDbContext.SaveChangesAsync();

            result.Succeeded = true;
            return(result);
        }
        // Handle Check Event By operator
        public async Task HandleCheckByOperator(int checkID, string user)
        {
            var check = _context.CheckModels.Include(o => o.ActiuneModel).FirstOrDefault(c =>
                                                                                         c.ActionCheckModelID == checkID);

            if (check != null)
            {
                check.IsCheckedByOp = !check.IsCheckedByOp;
                check.DataBifatByOp = DateTime.Now;
                check.Username      = user;
                _context.Update(check);

                await _context.SaveChangesAsync();
            }
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, [Bind("PersoanaModelID,Nume,Prenume,Email,Telefon,DataNastere,Sex,IsAcordGDPR")] PersoanaModel persoanaModel)
        {
            if (id != persoanaModel.PersoanaModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(persoanaModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersoanaModelExists(persoanaModel.PersoanaModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(persoanaModel));
        }
        public async Task <IActionResult> Edit(int id, [Bind("AntrenamentModelID,Data,OraStart,OraStop,IsPersonalTraining,Grupa")] AntrenamentModel antrenamentModel)
        {
            if (id != antrenamentModel.AntrenamentModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(antrenamentModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AntrenamentModelExists(antrenamentModel.AntrenamentModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(antrenamentModel));
        }
Пример #7
0
        public async Task <IActionResult> Edit(int id, [Bind("ResponsabilModelID,Nume,Prenume,Email,Functie,Departament")] ResponsabilModel responsabilModel)
        {
            if (id != responsabilModel.ResponsabilModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(responsabilModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ResponsabilModelExists(responsabilModel.ResponsabilModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(responsabilModel));
        }
Пример #8
0
        public async Task <IActionResult> Edit(int id, [Bind("UtilajModelID,Utilaj,ZonaUtilaj")] UtilajModel utilajModel)
        {
            if (id != utilajModel.UtilajModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(utilajModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UtilajModelExists(utilajModel.UtilajModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(utilajModel));
        }
        public async Task <ActionResult> Edit(int id, [Bind("ActiuneModelID,Descriere,Tip,IsUseInputText,InputText,UtilajModelID")] ActiuneModel actiuneModel)
        {
            if (id != actiuneModel.ActiuneModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(actiuneModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ActiuneModelExists(actiuneModel.ActiuneModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UtilajModelID"] = new SelectList(_context.UtilajModels, "UtilajModelID", "Utilaj", actiuneModel.UtilajModelID);
            return(View(actiuneModel));
        }
Пример #10
0
        public async Task <IActionResult> Edit(int id, [Bind("TipAbonamentModelID,Denumire,NrTotalSedinte,IsPersonalTraining,Pret")] TipAbonamentModel tipAbonamentModel)
        {
            if (id != tipAbonamentModel.TipAbonamentModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tipAbonamentModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipAbonamentModelExists(tipAbonamentModel.TipAbonamentModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipAbonamentModel));
        }
        // Update Nr sedinte efectuate
        // Daca o persoana a fost adaugata la un antrenament
        public void UpdateNrSedinteEfAbonamentbyID(int nr, int abonamentID, ReportDbContext context)
        {
            var abonamentModel = context.AbonamentModels
                                 .Include(t => t.TipAbonament)
                                 .Include(a => a.PersoanaModel)
                                 .FirstOrDefault(m => m.AbonamentModelID == abonamentID);

            abonamentModel.NrSedinteEfectuate += nr;

            context.Update(abonamentModel);
            context.SaveChanges();
        }
        public async Task <IActionResult> Edit(int id, [Bind("ProblemaModelID,DataIntroducere,UtilajModelID,ProblemaDescriere,ComentariuMentenanta,Stare,ResponsabilModelID,TermenFinalizare,LastPersonUpdateRow")] ProblemaModel problemaModel)
        {
            if (id != problemaModel.ProblemaModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Daca completeaza user Mentenanta se pune automat in lucru
                    if (User.IsInRole("Mentenanta") && problemaModel.Stare != Status.Rezolvat)
                    {
                        problemaModel.Stare = Status.InLucru;
                    }
                    // Se actualizeaza date server
                    _context.Update(problemaModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProblemaModelExists(problemaModel.ProblemaModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ResponsabilModelID"] = new SelectList(_context.ResponsabilModel, "ResponsabilModelID", "Email", problemaModel.ResponsabilModelID);
            ViewData["UtilajModelID"]      = new SelectList(_context.UtilajModels, "UtilajModelID", "Utilaj", problemaModel.UtilajModelID);
            return(View(problemaModel));
        }
Пример #13
0
        public async Task <IActionResult> Edit(int id, [Bind("AbonamentModelID,DataStart,DataStop,StareAbonament,NrSedinteEfectuate,TipAbonamentModelID,PersoanaModelID")] AbonamentModel abonamentModel)
        {
            if (id != abonamentModel.AbonamentModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Daca extindem abonament facem implicit abonament extins
                    if ((abonamentModel.DataStop - abonamentModel.DataStart).TotalDays > 32)
                    {
                        abonamentModel.StareAbonament = StareAbonament.Extins;
                    }

                    _context.Update(abonamentModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AbonamentModelExists(abonamentModel.AbonamentModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TipAbonamentModelID"] = new SelectList(_context.TipAbonamentModels, "TipAbonamentModelID", "Denumire", abonamentModel.TipAbonamentModelID);
            ViewData["PersoanaModelID"]     = new SelectList(_context.PersoanaModels, "PersoanaModelID", "NumeComplet", abonamentModel.PersoanaModelID);
            return(View(abonamentModel));
        }