public RequestResult <object> RemoveCompanyInvitation(InvitationCompanyModel model, PersonModel person)
        {
            TransactionOptions scp = new TransactionOptions();

            scp.IsolationLevel = IsolationLevel.ReadCommitted;


            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scp))
            {
                try
                {
                    var response = DelWithCompanyPerson(model, person);
                    if (response.Status != Status.Success)
                    {
                        throw new Exception("InvitationCompanyServices.RemoveCompanyInvitation: Error to delete the invitation - " + response.Message);
                    }
                    ts.Complete();
                    return(response);
                }
                catch (Exception ex)
                {
                    ts.Dispose();
                    throw new Exception("CompanyServices.RemoveCompany: Error to delete company - " + ex.Message);
                }
            }


            return(new RequestResult <object>());
        }
예제 #2
0
        private List <InvitationCompanyModel> GetInvitationsCompany(string email)
        {
            InvitationCompanyModel filters = new InvitationCompanyModel();
            var collection = serviceIn.Get(new PagerModel(0, 10, "", "", email), filters);

            return(collection);
        }
예제 #3
0
        public ActionResult Confirm(int?companyId)
        {
            try
            {
                InvitationCompanyServices invServ = new InvitationCompanyServices();
                InvitationCompanyModel    inv     = UserPerson.InvitationsCompanies.Find(x => x.CompanyId == companyId);
                inv.Status           = 1;
                UserPerson.CompanyId = inv.CompanyId;
                var result = invServ.ConfirmInvitation(inv, UserPerson);
                if (result == null || result.Status != Status.Success)
                {
                    throw new Exception(string.Format("{0}: {1}", localResource.txt_company_error_delete, result.Message));
                }
                SessionWeb.User.CompanyId = inv.CompanyId;
                foreach (var i in UserPerson.InvitationsCompanies)
                {
                    if (i.CompanyInvitationId == inv.CompanyInvitationId)
                    {
                        continue;
                    }
                    i.Status = 2;
                    invServ.InsUpd(i);
                }
                return(Json(result));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
예제 #4
0
        public List <InvitationCompanyModel> Get(PagerModel pager, InvitationCompanyModel filter)
        {
            using (var db = new EGULFEntities())
            {
                var resp = db.sp_SelInvitationsByCompanyId(filter.CompanyId, pager.Search, pager.Start, pager.Offset, pager.SortBy, pager.SortDir).ToList();

                if (resp.Count() > 0)
                {
                    var first = resp.FirstOrDefault();
                    pager.TotalRecords = first.TotalRecords.HasValue ? first.TotalRecords.Value : 0;
                }
                //return new List<InvitationCompanyModel>();
                return((from x in resp
                        select new InvitationCompanyModel()
                {
                    CompanyInvitationId = x.CompanyInvitationId,
                    CompanyId = x.CompanyId,
                    From = x.From,
                    To = x.To,
                    CreatedAt = x.created_at,
                    Status = x.status,
                    Email = x.Email,
                    FirstName = x.FirstName,
                    LastName = x.LastName,
                    CompanyName = x.CompanyName
                }).ToList());
            }
        }
예제 #5
0
        public ActionResult Delete(int id)
        {
            try
            {
                InvitationCompanyModel filters = new InvitationCompanyModel()
                {
                    CompanyId = UserCompanyId
                };
                DatatableModel dt = new DatatableModel()
                {
                    iColumns       = 5,
                    iDisplayLength = 10,
                    iDisplayStart  = 0,
                    iSortCol_0     = 3,
                    iSortingCols   = 1,
                    iTotalRecords  = 0,
                    sSearch        = null
                };
                var invitationsC = GetInvitationsCompany(dt, filters);
                if (invitationsC != null && invitationsC.Count() > 0)
                {
                    return(Json(new RequestResult <object>()
                    {
                        Status = Status.Warning, Message = localResource.txt_company_has_invitation
                    }));
                }

                CompanyServices cs = new CompanyServices();
                CompanyModel    cm = new CompanyModel()
                {
                    CompanyId = id,
                };
                if (cs.HasProjectsVesselsCompany(cm))
                {
                    return(Json(new RequestResult <object>()
                    {
                        Status = Status.Warning, Message = localResource.txt_company_has_vp
                    }));
                }

                var result = cs.RemoveCompany(cm, UserPerson);
                UserCompanyId = null;
                if (result.Status != Status.Success)
                {
                    throw new Exception(string.Format("{0}: {1}", localResource.txt_company_error_delete, result.Message));
                }
                return(Json(result));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
예제 #6
0
        public RequestResult <object> InsUpd(InvitationCompanyModel model)
        {
            using (var db = new EGULFEntities())
            {
                ObjectParameter Id = new ObjectParameter("CompanyInvitationId", typeof(int?));
                Id.Value = model.CompanyInvitationId;

                var ER = db.sp_InsUpdCompanyInvitation(Id, model.CompanyId, model.From, model.To, model.CreatedAt, model.Status, model.Email).
                         Select(x => new ErrorResult()
                {
                    IsError = x.IsError,
                    Message = x.Message,
                    Line    = x.Line,
                    Subject = x.Subject
                }).FirstOrDefault();
                //throw new Exception("Probando alert");
                if (ER != null && !string.IsNullOrEmpty(ER.Message))
                {
                    if (ER.IsError == true)
                    {
                        return new RequestResult <object>()
                               {
                                   Status = Status.Error, Message = ER.Message
                               }
                    }
                    ;
                    else
                    {
                        return new RequestResult <object>()
                               {
                                   Status = Status.Warning, Message = ER.Message
                               }
                    };
                }
                else
                {
                    model.CompanyInvitationId = Convert.ToInt32(Id.Value.ToString());
                    return(new RequestResult <object>()
                    {
                        Status = Status.Success, Data = model
                    });
                }
            }
        }
        public RequestResult <object> ConfirmInvitation(InvitationCompanyModel invitation, PersonModel person)
        {
            TransactionOptions scp = new TransactionOptions();

            scp.IsolationLevel = IsolationLevel.ReadCommitted;


            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scp))
            {
                try
                {
                    var response = InsUpd(invitation);
                    if (response.Status != Status.Success)
                    {
                        throw new Exception("InvitationCompanyServices.ConfirmInvitation: Error to update invitation - " + response.Message);
                    }
                    PersonServices psrv = new PersonServices();
                    var            p    = psrv.insUpdPerson(person);
                    if (response.Status != Status.Success)
                    {
                        throw new Exception("InvitationCompanyServices.ConfirmInvitation: Error to update person - " + response.Message);
                    }
                    CompanyServices CompanyServ = new CompanyServices();
                    CompanyServ.UpdateRolePerson(person.UserId, "UserCompanyRole");

                    ts.Complete();
                    return(response);
                }
                catch (Exception ex)
                {
                    ts.Dispose();
                    throw new Exception("InvitationCompanyServices.ConfirmInvitation: Error to confirm invitation - " + ex.Message);
                }
            }


            return(new RequestResult <object>()
            {
                Status = Status.Success
            });
        }
예제 #8
0
        private bool HasInvitation(string email, int?companyId)
        {
            InvitationCompanyModel filters = new InvitationCompanyModel()
            {
                Email = email, CompanyId = companyId
            };
            DatatableModel dt = new DatatableModel()
            {
                iColumns       = 5,
                iDisplayLength = 10,
                iDisplayStart  = 0,
                iSortCol_0     = 3,
                iSortingCols   = 1,
                iTotalRecords  = 0,
                sSearch        = email
            };
            InvitationCompanyServices service = new InvitationCompanyServices();
            PagerModel pager      = dt.ToPager();
            var        collection = service.Get(pager, filters).FirstOrDefault();

            HasRejectedInvitation = (collection != null && collection.Status == 2);
            return(collection != null);
        }
예제 #9
0
        public ActionResult DeleteInvivtation(int id, string email)
        {
            try
            {
                PersonServices persnServ = new PersonServices();
                var            p         = persnServ.getFirstUserPerson(new UserPersonModel()
                {
                    Email = email
                });
                InvitationCompanyServices cs = new InvitationCompanyServices();
                InvitationCompanyModel    cm = new InvitationCompanyModel()
                {
                    CompanyInvitationId = id,
                    From = p.PersonId
                };
                PagerModel pager       = new PagerModel(0, 100, "", "");
                var        invitations = cs.Get(pager, cm);
                cm = invitations.Find(x => x.To == p.PersonId);
                var result = (p != null && p.CompanyId == UserCompanyId) ? cs.RemoveCompanyInvitation(cm, p.ToPerson()) : cs.Del(cm);
                if (p != null && cm.Status != 2)
                {
                    SendNotificationsInvite(p.PersonId, 3);
                }
                if (result.Status != Status.Success)
                {
                    throw new Exception(string.Format("{0}: {1}", localResource.txt_error_remove_invitation, result.Message));
                }
                return(Json(result));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
예제 #10
0
     public RequestResult <object> Del(InvitationCompanyModel model)
     {
         using (var db = new EGULFEntities())
         {
             var ER = db.sp_delCompanyInvitation(model.CompanyInvitationId).
                      Select(x => new ErrorResult()
             {
                 IsError = x.IsError,
                 Message = x.Message,
                 Line    = x.Line,
                 Subject = x.Subject
             }).FirstOrDefault();
             if (ER != null && !string.IsNullOrEmpty(ER.Message))
             {
                 if (ER.IsError == true)
                 {
                     return new RequestResult <object>()
                            {
                                Status = Status.Error, Message = ER.Message
                            }
                 }
                 ;
                 else
                 {
                     return new RequestResult <object>()
                            {
                                Status = Status.Warning, Message = ER.Message
                            }
                 };
             }
             return(new RequestResult <object>()
             {
                 Status = Status.Success, Data = model
             });
         }
     }
 }
예제 #11
0
        public ActionResult GetInvitation(DatatableModel dt, InvitationCompanyModel filters)
        {
            try
            {
                PagerModel pager      = dt.ToPager();
                var        collection = GetInvitationsCompany(dt, filters);

                return(Json(new
                {
                    status = UI.Status.Success,
                    sEcho = dt.sEcho,
                    iTotalRecords = pager.TotalRecords,
                    iTotalDisplayRecords = pager.TotalRecords,
                    aaData = collection
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
예제 #12
0
        private List <InvitationCompanyModel> GetInvitationsCompany(DatatableModel dt, InvitationCompanyModel filters)
        {
            filters.CompanyId = UserCompanyId;
            InvitationCompanyServices service = new InvitationCompanyServices();
            PagerModel pager = dt.ToPager();

            return(service.Get(pager, filters));
        }
예제 #13
0
        public RequestResult <object> InsUpd(InvitationCompanyModel model)
        {
            InvitationCompanyDA da = new InvitationCompanyDA();

            return(da.InsUpd(model));
        }
예제 #14
0
        public List <InvitationCompanyModel> Get(PagerModel pager, InvitationCompanyModel filter)
        {
            InvitationCompanyDA da = new InvitationCompanyDA();

            return(da.Get(pager, filter));
        }
예제 #15
0
        public RequestResult <object> DelWithCompanyPerson(InvitationCompanyModel model, PersonModel person)
        {
            InvitationCompanyDA da = new InvitationCompanyDA();

            return(da.Del(model, person));
        }