Exemplo n.º 1
0
        public int AddCase(CreateCaseViewModel @case)
        {
            Person leadClient;

            if (@case.LeadClient.Id == 0)
            {
                leadClient = new Person
                {
                    FirstName   = @case.LeadClient.FirstName,
                    LastName    = @case.LeadClient.LastName,
                    DateOfBirth = @case.LeadClient.DateOfBirth,
                    Gender      = @case.LeadClient.Gender,
                    Nationality = @case.LeadClient.Nationality,
                    Notes       = @case.LeadClient.Notes,
                    AlienNumber = @case.LeadClient.AlienNumber.TrimStart('A').Trim()
                };
                _db.People.Add(leadClient);
                _db.SaveChanges();
            }
            else
            {
                leadClient = GetPerson(@case.LeadClient.Id);
            }
            var assigningAttorney = _db.Attorneys.Find(@case.AssigningAttorneyId);
            var newCase           = new Case
            {
                Active            = true,
                AssigningAttorney = assigningAttorney,
                CaseNotes         = @case.CaseNotes,
                LeadClient        = leadClient,
                Type        = @case.Type,
                DateCreated = DateTime.Now
            };

            _db.Cases.Add(newCase);
            newCase.CaseEvents = new List <CaseEvent>();
            if (@case.CaseEvents != null)
            {
                foreach (var caseEvent in @case.CaseEvents)
                {
                    newCase.CaseEvents.Add(new CaseEvent
                    {
                        EventDate = caseEvent.EventDate,
                        Event     = caseEvent.Event
                    });
                }
                _db.SaveChanges();
            }
            var createdLog = new CaseLogEntry
            {
                CaseId     = newCase.Id,
                EntryDate  = DateTime.Today,
                EntryNotes = "Case Created"
            };

            _db.LogEntries.Add(createdLog);
            _db.SaveChanges();
            return(newCase.Id);
        }
 public int InsertAttorney(string userID, CreateCaseViewModel vm)
 {
     return(InsertAttorney(userID,
                           vm.AttorneyFirstName,
                           vm.AttorneyLastName,
                           vm.AttorneyAFM,
                           vm.AttorneyCity));
 }
Exemplo n.º 3
0
 public int InsertPartyDefense(string userID, CreateCaseViewModel vm)
 {
     return(InsertParty(userID,
                        vm.DefenseFirstName,
                        vm.DefenseLastName,
                        vm.DefenseFathersName,
                        2));
 }
Exemplo n.º 4
0
 public int InsertPartyRecipient(string userID, CreateCaseViewModel vm)
 {
     return(InsertParty(userID,
                        vm.RecipientFirstName,
                        vm.RecipientLastName,
                        vm.RecipientFathersName,
                        3));
 }
Exemplo n.º 5
0
 public int InsertPartyProsecution(string userID, CreateCaseViewModel vm)
 {
     return(InsertParty(userID,
                        vm.ProsecutionFirstName,
                        vm.ProsecutionLastName,
                        vm.ProsecutionFathersName,
                        1));
 }
Exemplo n.º 6
0
        // GET: Cases/Create
        public IActionResult Create()
        {
            var newCase = new CreateCaseViewModel
            {
                Active = true
            };

            return(View());
        }
Exemplo n.º 7
0
        public ActionResult Create()
        {
            userID = User.Identity.GetUserId();

            CreateCaseViewModel vm = new CreateCaseViewModel();

            vm.PrepareLists(userID);

            return(View(vm));
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Create([Bind(Include = "Title, Description")] CreateCaseViewModel createCaseViewModel)
        {
            var now = System.DateTime.Now;

            if (ModelState.IsValid)
            {
                var @case = new Case
                {
                    Title       = createCaseViewModel.Title,
                    Description = createCaseViewModel.Description,
                    CreatedAt   = now,
                    UpdatedAt   = now,
                    CreatedBy   = CurrentUser,
                    State       = CaseState.NEW,
                    OldState    = CaseState.CLOSED,
                };

                Database.Cases.Add(@case);
                await Database.SaveChangesAsync();

                string roleName = (await UserManager.GetRolesAsync(CurrentUser.Id)).Single();
                @case.Title = string.Format("CASE-{0}-{1}-{2,5:00000}: {3}",
                                            roleName.Substring(0, 1).ToUpper(),
                                            CultureHelper.GetCurrentCountryCode(),
                                            @case.ID,
                                            @case.Title);
                await Database.SaveChangesAsync();

                // successfully create a new case, send a message to manager
                var    managers = UserService.FindUsersByRoleName("manager").ToList();
                string From     = ConfigurationManager.AppSettings["MailSentFrom"];
                string To       = string.Join(",", managers.Select(m => m.Email));
                string Subject  = string.Format(Resources.Resources.CaseCreatedSubject, @case.CreatedBy.UserName, @case.Title);
                string linkUrl  = Url.Action("Edit", "Cases", new { id = @case.ID }, this.Request.Url.Scheme);
                string Message  = string.Format(Resources.Resources.CaseCreatedMessage,
                                                @case.CreatedBy.UserName,
                                                @case.CreatedAt,
                                                "<a href='" + linkUrl + "'>" + linkUrl + "</a>");
                MessageService.SendMailAsync(From, To, Subject, Message);

                return(RedirectToAction("Edit", new { id = @case.ID }));
            }

            return(View());
        }
Exemplo n.º 9
0
        public IActionResult Create(CreateCaseViewModel @case)
        {
            if (ModelState.IsValid)
            {
                var caseId = _context.AddCase(@case);
                return(RedirectToAction("Details", new { id = caseId }));
            }
            else
            {
                if (@case.AssigningAttorneyId == 0)
                {
                    ModelState.AddModelError("AssigningAttorneyId", "An Assigning Attorney must be selected.");
                }

                if (ModelState.ErrorCount == 1 && @case.LeadClient.Id == 0)
                {
                    var caseId = _context.AddCase(@case);
                    return(RedirectToAction("Details", new { id = caseId }));
                }
            }
            return(Create());
        }
Exemplo n.º 10
0
        public ActionResult Create(CreateCaseViewModel vm)
        {
            userID = User.Identity.GetUserId();

            if (db.Cases.Any(x => x.Aa == vm.Aa && x.UserId == userID) || !ModelState.IsValid)
            {
                vm.PrepareLists(userID);
                return(View(vm));
            }

            if (vm.newAttorney)
            {
                vm.AttorneyId = AttorneyRepository.InsertAttorney(userID, vm);
            }

            if (vm.newCourt)
            {
                vm.CourtId = CourtRepository.InsertCourt(userID, vm);
            }

            if (vm.newProsecution)
            {
                vm.ProsecutionId = PartyRepository.InsertPartyProsecution(userID, vm);
            }

            if (vm.newDefense)
            {
                vm.DefenseId = PartyRepository.InsertPartyDefense(userID, vm);
            }

            if (vm.newRecipient)
            {
                vm.RecipientId = PartyRepository.InsertPartyRecipient(userID, vm);
            }

            CaseRepository.InsertCaseFromViewModel(userID, vm);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public ActionResult Create([Bind(Include = "Reference,Postcode,AddressLine1,AddressLine2,Country")] CreateCaseViewModel @case, string DropDownInstruction, string DropDownCities, string DropDownTemplates)
        {
            if (string.Compare(DropDownInstruction, Instruction.Buy.ToString()) == 0)
            {
                @case.Instruction = Instruction.Buy;
            }
            else
            {
                @case.Instruction = Instruction.Sell;
            }
            @case.City = DropDownCities;
            int TemplateID = Convert.ToInt16(DropDownTemplates);

            if (ModelState.IsValid)
            {
                Case newCase = new Case();
                newCase.Instruction       = @case.Instruction;
                newCase.Reference         = @case.Reference;
                newCase.AddressLine1      = @case.AddressLine1;
                newCase.AddressLine2      = @case.AddressLine2;
                newCase.CityID            = Convert.ToInt16(@case.City);
                newCase.Country           = @case.Country;
                newCase.Postcode          = RemoveSpace(@case.Postcode);
                newCase.CaseName          = @case.Instruction + "_" + newCase.Postcode + "_" + @case.Reference;
                newCase.CreateDateTime    = (DateTime)DateTime.Now;
                newCase.StartDateA        = newCase.CreateDateTime;
                newCase.SolicitorID       = User.Identity.GetUserId();
                newCase.TemplateID        = TemplateID;
                newCase.ClientModuleSetID = CreateClientModules(newCase.SolicitorID + newCase.CaseName, newCase.Instruction, TemplateID);
                db.Cases.Add(newCase);
                db.SaveChanges();


                Case addedCase = db.Cases.FirstOrDefault(p => p.CaseName == newCase.CaseName && p.ClientModuleSetID == newCase.ClientModuleSetID);
                //Create a new folder for case
                string path = Path.Combine(Server.MapPath("~/Upload/"), newCase.CaseName + "_" + addedCase.CaseID);
                if (!Directory.Exists(path))
                {
                    // Try to create the directory.
                    DirectoryInfo di = Directory.CreateDirectory(path);
                }
                //log new case creation
                log("created new case : " + addedCase.CaseName, addedCase.CaseID);
                return(RedirectToAction("Index"));
            }
            ViewBag.ErrorMsg = "Creating new case failed, please try again later";
            //populate instruction dropdownlist
            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem {
                Text = "Buy", Value = Instruction.Buy.ToString()
            });
            items.Add(new SelectListItem {
                Text = "Sell", Value = Instruction.Sell.ToString()
            });
            ViewBag.DropDownInstruction = items;

            //populate city dropdownlist
            var Cities = db.City.ToList();
            List <SelectListItem> cityItems = new List <SelectListItem>();

            foreach (City c in Cities)
            {
                cityItems.Add(new SelectListItem {
                    Text = c.CityName, Value = c.CityID.ToString()
                });
            }
            //populate template dropdownlist
            var Templates = db.Template.ToList();
            List <SelectListItem> templateItems = new List <SelectListItem>();

            foreach (Template t in Templates)
            {
                templateItems.Add(new SelectListItem {
                    Text = t.Name, Value = t.TemplateID.ToString()
                });
            }
            ViewBag.DropDownTemplates = templateItems;

            ViewBag.DropDownCities = cityItems;
            ViewBag.UserID         = User.Identity.GetUserId();
            return(View());
        }
Exemplo n.º 12
0
 public int InsertCourt(string userID, CreateCaseViewModel vm)
 {
     return(InsertCourt(userID, vm.CourtName));
 }