Beispiel #1
0
        public ModelResponse PostAnOpportunity(ref OpportunityVm r)
        {
            try
            {
                if (r.Title.IsNullOrWhiteSpace())
                {
                    return(Factory.ModelResponse(1));
                }

                if (r.StartDate < DateTime.Today || r.EndDate < r.StartDate)
                {
                    return(Factory.ModelResponse(2));
                }

                if (_repo.IsDuplicate(r))
                {
                    return(Factory.ModelResponse(3));
                }

                if (!string.IsNullOrWhiteSpace(r.FilePath))
                {
                    r.Approval = Approval.Pending;
                    _repo.PostAnOpportunity(ref r, UserId);
                }
            }
            catch (Exception ex)
            {
                return(Factory.ModelResponse(ex));
            }

            return(Factory.ModelResponse(0));
        }
Beispiel #2
0
        public bool IsDuplicate(ref OpportunityVm vm)
        {
            var id        = vm.OpportunityId;
            var startDate = vm.StartDate;
            var titles    = vm.Title.ToLowerTrimmedStrings();

            using (var db = new LMISEntities())
            {
                return(db.Opportunities
                       .Include(r => r.OpportunitiesDetails)
                       .Any(r => r.IsDeleted == null && r.OpportunityID != id && r.StartDate == startDate &&
                            r.OpportunitiesDetails
                            .Any(d => titles.Contains(d.OpportunityTitle.Trim().ToLower()))));
            }
        }
Beispiel #3
0
        public static object PostAnOpportunity(OpportunityVm data, bool validateOnly)
        {
            if (DalFactory.Singleton.DataService.IsAdmin(Utils.LoggedUser.UserId))
            {
                if (data.OpportunityId > 0)
                {
                    if (Utils.CheckPermission(3, 92, Utils.LoggedUser.Roles) < 1)
                    {
                        return(Utils.ServiceResponse(PageCode, new ModelResponse(101), null));
                    }
                }
                else
                {
                    if (Utils.CheckPermission(2, 92, Utils.LoggedUser.Roles) < 1)
                    {
                        return(Utils.ServiceResponse(PageCode, new ModelResponse(101), null));
                    }
                }
            }

            var mr = Mgr.Post(Utils.LoggedUser, ref data, Utils.UploadFolder, validateOnly);

            return(Utils.ServiceResponse(PageCode, mr));
        }
Beispiel #4
0
        public long Post(ref OpportunityVm vm, string userId)
        {
            using (var db = new LMISEntities())
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var id = vm.OpportunityId;

                        if (id > 0) //Update
                        {
                            var tr = db.Opportunities
                                     .Where(r => r.IsDeleted == null && r.OpportunityID == id)
                                     .ToList().Single();

                            tr.OrganizationContactID = vm.ContactId;
                            tr.OpportunityFilePath   = vm.FilePath;
                            tr.StartDate             = vm.StartDate.AsUtc();
                            tr.EndDate      = vm.EndDate.AsUtc();
                            tr.Is_Approved  = (byte)vm.Approval;
                            tr.IsInformal   = vm.IsInformal;
                            tr.IsInternal   = vm.IsInternal;
                            tr.UpdateUserID = userId;
                            tr.UpdateDate   = DateTime.UtcNow;

                            //Delete detail records
                            var dr = db.OpportunitiesDetails
                                     .Where(r => r.OpportunityID == id)
                                     .ToList();

                            db.OpportunitiesDetails.RemoveRange(dr);
                        }
                        else        //Insert
                        {
                            var tr = new Opportunity
                            {
                                OrganizationContactID = vm.ContactId,
                                OpportunityFilePath   = vm.FilePath,
                                StartDate             = vm.StartDate.AsUtc(),
                                EndDate     = vm.EndDate.AsUtc(),
                                Is_Approved = (byte)vm.Approval,
                                IsInformal  = vm.IsInformal,
                                IsInternal  = vm.IsInternal,
                                PostUserID  = userId,
                                PostDate    = DateTime.UtcNow
                            };

                            db.Opportunities.Add(tr);
                            db.SaveChanges();

                            vm.OpportunityId = (long)tr.OpportunityID;
                        }

                        //Insert detail records
                        foreach (var r in vm.Title.ToLocalStrings())
                        {
                            var dr = new OpportunitiesDetail()
                            {
                                OpportunityID    = vm.OpportunityId,
                                LanguageID       = r.L,
                                OpportunityTitle = r.T
                            };
                            db.OpportunitiesDetails.Add(dr);
                        }

                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        ExceptionDispatchInfo.Capture(ex).Throw();
                    }
                }

            return(vm.OpportunityId);
        }
Beispiel #5
0
        public ModelResponse Post(UserInfo user, ref OpportunityVm vm, string fileFolder, bool validateOnly)
        {
            try
            {
                //Authorization
                if (user == null)
                {
                    return(new ModelResponse(101));
                }
                if (string.IsNullOrWhiteSpace(user.UserId))
                {
                    return(new ModelResponse(101));
                }
                if (!user.IsApproved || user.IsIndividual || user.OrgContactId == null)
                {
                    return(new ModelResponse(101));
                }

                var isAdmin = DalFactory.Singleton.DataService.IsAdmin(user.UserId);
                if (isAdmin && vm.OpportunityId > 0 && !Repo.IsInternal(vm.OpportunityId))
                {
                    return(new ModelResponse(101));
                }
                if (!isAdmin && vm.OpportunityId > 0 && !Repo.IsByOrgContact(vm.OpportunityId, (long)user.OrgContactId))
                {
                    return(new ModelResponse(101));
                }

                //Validations
                if (vm.Title.IsNullOrWhiteSpace())
                {
                    return(new ModelResponse(1));
                }
                if ((vm.OpportunityId < 1 && vm.StartDate < DateTime.Today) || vm.EndDate < vm.StartDate)
                {
                    return(new ModelResponse(2));
                }
                if (Repo.IsDuplicate(ref vm))
                {
                    return(new ModelResponse(3));
                }

                if (!validateOnly)
                {
                    //Verify File Path
                    if (string.IsNullOrWhiteSpace(fileFolder))
                    {
                        return(new ModelResponse(102));
                    }
                    if (string.IsNullOrWhiteSpace(vm.FilePath))
                    {
                        return(new ModelResponse(102));
                    }
                    if (!File.Exists(Path.Combine(fileFolder, vm.FilePath)))
                    {
                        return(new ModelResponse(102));
                    }

                    //Save to DB
                    vm.Approval = isAdmin ? Approval.Approved : Approval.Pending;
                    if (!isAdmin)
                    {
                        vm.IsInformal = false;
                    }
                    vm.IsInternal = isAdmin;
                    vm.ContactId  = (long)user.OrgContactId;
                    Repo.Post(ref vm, user.UserId);
                }
            }
            catch (Exception ex)
            {
                return(new ModelResponse(ex));
            }

            return(new ModelResponse(0, vm.OpportunityId));
        }