Ejemplo n.º 1
0
        public async Task <IActionResult> noteHoliday([FromQuery] DateTime dt)
        {
            try
            {
                var holiday = await _context.Holidays.Where(m => m.Date.Year == dt.Year && m.Date.Month == dt.Month && m.Date.Day == dt.Day).FirstOrDefaultAsync();

                if (holiday != null)
                {
                    _context.Holidays.Remove(holiday);
                }
                else
                {
                    await _context.Holidays.AddAsync(new Holiday
                    {
                        Date = dt
                    });
                }
                await _context.SaveChangesAsync();

                return(Json(HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(View(nameof(Index)));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(SliderCreateModel slider)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = await FileService.UploadImageAsync(slider.Img, "Uploads");

                    await lawyerDbContext.Sliders.AddAsync(new Slider
                    {
                        Img = fileName
                    });

                    await lawyerDbContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (ArgumentNullException exp)
                {
                    ModelState.AddModelError("img", exp.Message);
                }

                catch (InvalidContentTypeException exp)
                {
                    ModelState.AddModelError("img", exp.Message);
                }
                catch
                {
                    ModelState.AddModelError("", "Some error occured. Please try again.");
                }
            }
            return(View(slider));
        }
        public async Task <IActionResult> Delete([Required][FromForm] int id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Message message = await lawyerDbContext.Messages.FindAsync(id);

                    if (message == null)
                    {
                        throw new NullReferenceException();
                    }

                    lawyerDbContext.Messages.Remove(message);
                    await lawyerDbContext.SaveChangesAsync();

                    return(Json(new
                    {
                        status = HttpStatusCode.OK
                    }));
                }
                catch { }
            }
            return(Json(new
            {
                status = HttpStatusCode.NotFound
            }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ScheduleDay(ScheduleViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    int      teamId   = Convert.ToInt32(HttpContext.Session.GetInt32("user"));
                    DateTime date     = Convert.ToDateTime(HttpContext.Session.GetString("date"));
                    var      schedule = new Schedule
                    {
                        Name         = model.Name,
                        Surname      = model.Surname,
                        Message      = model.Message,
                        Email        = model.Email,
                        Phone        = model.Phone,
                        TeammemberId = teamId,
                        Date         = date
                    };
                    await _context.Schedules.AddAsync(schedule);

                    await _context.SaveChangesAsync();

                    return(View(nameof(Result)));
                }
                catch (Exception)
                {
                    return(View());
                }
            }
            return(View());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Contact([FromRoute] string culture, MessageSendModel Message)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await lawyerDbContext.Messages.AddAsync(new Message
                    {
                        Email          = Message.Email,
                        Name           = Message.Name,
                        MessageContent = Message.Message,
                        Subject        = Message.Subject,
                    });

                    await lawyerDbContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(Contact)));
                }
                catch
                {
                    return(BadRequest());
                }
            }

            try
            {
                int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext, culture);

                if (languageId == null)
                {
                    return(NotFound());
                }

                var contact = (await lawyerDbContext.GetContactViewAsync()).SingleOrDefault(m => m.LanguageId == languageId);

                ContactsViewModel contactsViewModel = new ContactsViewModel
                {
                    Email   = contact.ContactEmail,
                    Number  = contact.ContactNumber,
                    Address = contact.ContactAdress
                };
                return(View(contactsViewModel));
            }
            catch
            {
                return(NotFound());
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit([Required][FromForm] int id, ContactEditModel contactEditModel)
        {
            if (ModelState.IsValid)
            {
                IDbContextTransaction transaction = null;
                try
                {
                    transaction = await lawyerDbContext.Database.BeginTransactionAsync();

                    StaticData staticData = await lawyerDbContext.StaticDatas.FindAsync(id);

                    if (staticData == null)
                    {
                        throw new NullReferenceException();
                    }

                    staticData.ContactEmail      = contactEditModel.ContactEmail;
                    staticData.ContactNumber     = contactEditModel.ContactNumber;
                    staticData.ContactHomeNumber = contactEditModel.ContactHomeNumber;

                    IEnumerable <Text> adressTextAllLanguage = await lawyerDbContext.Texts
                                                               .Where(m => m.Key == staticData.ContactAdressKey)
                                                               .ToListAsync();

                    //Update texts all language for properties
                    foreach (var item in contactEditModel.ContactAdresses)
                    {
                        Text adress = adressTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId);
                        adress.TextContent = item.ContactAdress;
                    }

                    await lawyerDbContext.SaveChangesAsync();

                    transaction.Commit();

                    return(RedirectToAction(nameof(Index)));
                }

                catch (NullReferenceException exp)
                {
                    ModelState.AddModelError("", exp.Message);
                }

                catch
                {
                    transaction.Rollback();

                    ModelState.AddModelError("", "Some error occured. Please try again.");
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                }
            }

            ContactViewModel contactViewModel = new ContactViewModel
            {
                Id              = id,
                ContactEmail    = contactEditModel.ContactEmail,
                ContactNumber   = contactEditModel.ContactNumber,
                ContactAdresses = contactEditModel.ContactAdresses,
                Languages       = await lawyerDbContext.Languages
                                  .AsNoTracking()
                                  .ToListAsync()
            };

            return(View(contactViewModel));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create(List <TeamMemberCreateModel> TeamMembers, [FromForm] byte Begin, [FromForm] byte End, IFormFile Img, List <int> AreaId)
        {
            if (ModelState.IsValid)
            {
                //Begin Transaction
                IDbContextTransaction transaction = null;
                try
                {
                    transaction = await lawyerDbContext.Database.BeginTransactionAsync();

                    // Generated key for each text
                    TeamMember teamMember = new TeamMember();
                    teamMember.NameKey        = DbContextService.GenerateKey("name");
                    teamMember.SurnameKey     = DbContextService.GenerateKey("surname");
                    teamMember.DescriptionKey = DbContextService.GenerateKey("desc");


                    teamMember.Img = await FileService.UploadImageAsync(Img, "Uploads");

                    teamMember.Begin = Begin;
                    teamMember.End   = End;

                    //Add name with different language
                    IEnumerable <Text> nameDiffLangForText = TeamMembers.Select(m => new Text
                    {
                        Key         = teamMember.NameKey,
                        TextContent = m.Name,
                        LanguageId  = m.LanguageId
                    });

                    await lawyerDbContext.Texts.AddRangeAsync(nameDiffLangForText);

                    //Add surname with different language
                    IEnumerable <Text> surnameDiffLangForText = TeamMembers.Select(m => new Text
                    {
                        Key         = teamMember.SurnameKey,
                        TextContent = m.Surname,
                        LanguageId  = m.LanguageId
                    });

                    await lawyerDbContext.Texts.AddRangeAsync(surnameDiffLangForText);

                    //Add description with different language
                    IEnumerable <Text> descriptionDiffLangForText = TeamMembers.Select(m => new Text
                    {
                        Key         = teamMember.DescriptionKey,
                        TextContent = m.Description,
                        LanguageId  = m.LanguageId
                    });
                    await lawyerDbContext.Texts.AddRangeAsync(descriptionDiffLangForText);

                    await lawyerDbContext.AddAsync(teamMember);

                    await lawyerDbContext.SaveChangesAsync();

                    IEnumerable <TeamToArea> teamToAreas = AreaId.Select(m => new TeamToArea
                    {
                        AreaId       = m,
                        TeamMemberId = teamMember.Id
                    });

                    await lawyerDbContext.AddRangeAsync(teamToAreas);

                    await lawyerDbContext.SaveChangesAsync();

                    transaction.Commit();

                    return(RedirectToAction(nameof(Index)));
                }

                catch (ArgumentNullException exp)
                {
                    ModelState.AddModelError("img", exp.Message);
                }

                catch (InvalidContentTypeException exp)
                {
                    ModelState.AddModelError("img", exp.Message);
                }

                catch
                {
                    transaction.Rollback();

                    ModelState.AddModelError("", "Some error occured ! Please try again.");
                }

                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                }
            }

            TeamMemberViewModel teamMemberViewModel = new TeamMemberViewModel
            {
                Languages = await lawyerDbContext.Languages
                            .AsNoTracking()
                            .ToListAsync(),
                Areas = (await lawyerDbContext.GetAreaViewAsync())
                        .Where(m => m.LanguageId == DbContextService.GetLanguageIdByShortName(lawyerDbContext)).ToList()
            };

            return(View(teamMemberViewModel));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit([Required][FromForm] int id, FirmEditModel firmEditModel)
        {
            if (ModelState.IsValid)
            {
                IDbContextTransaction transaction = null;
                try
                {
                    transaction = await lawyerDbContext.Database.BeginTransactionAsync();

                    StaticData staticData = await lawyerDbContext.StaticDatas.FindAsync(id);

                    if (staticData == null)
                    {
                        throw new NullReferenceException("This firm doesn't exist. ");
                    }

                    if (firmEditModel.Img != null)
                    {
                        string fileName = staticData.OurFirmImg;
                        staticData.OurFirmImg = await FileService.UploadImageAsync(firmEditModel.Img, "Uploads");

                        FileService.DeleteFile(fileName, "Uploads");
                    }

                    IEnumerable <Text> titleTextAllLanguage = await lawyerDbContext.Texts
                                                              .Where(m => m.Key == staticData.OurFirmTitleKey)
                                                              .ToListAsync();

                    IEnumerable <Text> descriptionTextAllLanguage = await lawyerDbContext.Texts
                                                                    .Where(m => m.Key == staticData.OurFirmDescriptionKey)
                                                                    .ToListAsync();

                    //Update texts all language for properties
                    foreach (var item in firmEditModel.Firms)
                    {
                        Text title = titleTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId);
                        title.TextContent = item.Title;
                    }

                    foreach (var item in firmEditModel.Firms)
                    {
                        Text description = descriptionTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId);
                        description.TextContent = item.Description;
                    }



                    await lawyerDbContext.SaveChangesAsync();

                    transaction.Commit();

                    return(RedirectToAction(nameof(Index)));
                }

                catch (NullReferenceException exp)
                {
                    ModelState.AddModelError("", exp.Message);
                }

                catch (ArgumentNullException exp)
                {
                    ModelState.AddModelError("img", exp.Message);
                }

                catch (InvalidContentTypeException exp)
                {
                    ModelState.AddModelError("img", exp.Message);
                }
                catch
                {
                    transaction.Rollback();

                    ModelState.AddModelError("", "Some error occured. Please try again.");
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                }
            }

            FirmViewModel firmViewModel = new FirmViewModel
            {
                Id        = id,
                Img       = null,
                Firms     = firmEditModel.Firms,
                Languages = await lawyerDbContext.Languages
                            .AsNoTracking()
                            .ToListAsync()
            };

            return(View(firmViewModel));
        }
        public async Task <IActionResult> Edit([Required][FromForm] int id, AboutEditModel aboutEditModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    StaticData staticData = await lawyerDbContext.StaticDatas.FindAsync(id);

                    if (staticData == null)
                    {
                        throw new NullReferenceException("This firm doesn't exist. ");
                    }

                    IEnumerable <Text> teamDescTextAllLanguage = await lawyerDbContext.Texts
                                                                 .Where(m => m.Key == staticData.OurTeamDescriptionKey)
                                                                 .ToListAsync();

                    IEnumerable <Text> serviceDescTextAllLanguage = await lawyerDbContext.Texts
                                                                    .Where(m => m.Key == staticData.ServicesDescriptionKey)
                                                                    .ToListAsync();

                    //Update texts all language for properties
                    foreach (var item in aboutEditModel.TeamServices)
                    {
                        Text team = teamDescTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId);
                        team.TextContent = item.OurTeamDescription;
                    }

                    foreach (var item in aboutEditModel.TeamServices)
                    {
                        Text service = serviceDescTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId);
                        service.TextContent = item.OurServicesDescription;
                    }

                    await lawyerDbContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }

                catch (NullReferenceException exp)
                {
                    ModelState.AddModelError("", exp.Message);
                }

                catch
                {
                    ModelState.AddModelError("", "Some error occured. Please try again.");
                }
            }

            AboutViewModel aboutViewModel = new AboutViewModel
            {
                Id           = id,
                TeamServices = aboutEditModel.TeamServices,
                Languages    = await lawyerDbContext.Languages
                               .AsNoTracking()
                               .ToListAsync()
            };

            return(View(aboutViewModel));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create(AreaCreateModel areaCreateModel)
        {
            if (ModelState.IsValid)
            {
                IDbContextTransaction transaction = null;

                try
                {
                    transaction = await lawyerDbContext.Database.BeginTransactionAsync();

                    Area area = new Area
                    {
                        NameKey        = DbContextService.GenerateKey("area_name"),
                        DescriptionKey = DbContextService.GenerateKey("desc"),
                        MeetingMinute  = areaCreateModel.MeetingMinute,
                    };

                    IEnumerable <Text> areaNameForAllLangueges = areaCreateModel.Areas.Select(m => new Text
                    {
                        Key         = area.NameKey,
                        TextContent = m.Name,
                        LanguageId  = m.LanguageId
                    });

                    await lawyerDbContext.Texts.AddRangeAsync(areaNameForAllLangueges);

                    IEnumerable <Text> areaDescriptionForAllLangueges = areaCreateModel.Areas.Select(m => new Text
                    {
                        Key         = area.DescriptionKey,
                        TextContent = m.Description,
                        LanguageId  = m.LanguageId
                    });

                    await lawyerDbContext.Areas.AddAsync(area);

                    await lawyerDbContext.Texts.AddRangeAsync(areaDescriptionForAllLangueges);

                    await lawyerDbContext.SaveChangesAsync();

                    transaction.Commit();

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    transaction.Rollback();

                    ModelState.AddModelError("", "Some error occured ! Please try again .");
                }

                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                }
            }

            AreaViewModel areaViewModel = new AreaViewModel
            {
                Languages = await lawyerDbContext.Languages
                            .AsNoTracking()
                            .ToListAsync(),
                Areas         = areaCreateModel.Areas,
                MeetingMinute = areaCreateModel.MeetingMinute
            };

            return(View(areaViewModel));
        }