public int UpdateDelivered(int OrderNo)
        {
            this.CheckAccess();
            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                using (var dbContextTransaction = entity.Database.BeginTransaction())
                {
                    try
                    {
                        var query =
                            from ord in entity.BookingDetails
                            where ord.BookingID == OrderNo
                            select ord;

                        // Execute the query, and change the column values
                        // you want to change.
                        foreach (var ord in query)
                        {
                            ord.IsDeliver = true;
                            // Insert any additional changes to column values.
                        }
                        entity.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                        return(0);
                    }
                }
            }
            return(1);
        }
Пример #2
0
        public string CreateNewUserGroup(string userGroupName)
        {
            UserGroup _userGroup = new UserGroup();
            string    message    = "";

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                var Isalready = entity.UserGroups.Where(w => w.UserGroupName.Trim().ToUpper() == userGroupName.Trim().ToUpper()).Count();
                if (Isalready > 0)
                {
                    message = "Already exist";
                }
                else
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        _userGroup.UserGroupName = userGroupName;


                        entity.UserGroups.Add(_userGroup);
                        entity.SaveChanges();
                        scope.Complete();
                        message = "Succesfully Added";
                    }
                }
            }
            return(message);
        }
        public string BookingSendMessage(int bookingID = 0)
        {
            //get list of message
            var result = "";
            BraathenEiendomEntities entity = new BraathenEiendomEntities();
            var list = entity.BookingMessages.Where(w => w.Status == 0 &&
                                                    (bookingID == 0 || bookingID != 0 && w.BookingID == bookingID) &&
                                                    (w.SendTime == null || w.SendTime <= DateTime.Now)).ToList();

            result += "Found records: " + list.Count + ".";
            foreach (var message in list)
            {
                result += "Sending " + message.ID + ".";
                var messageType = 0;
                if (message.Type == "email")
                {
                    messageType = 1;
                }
                else if (message.Type == "sms")
                {
                    messageType = 2;
                }

                var toArray = message.To.Split(';');
                var to      = new Dictionary <string, string[]>();
                foreach (var item in toArray)
                {
                    to.Add(item, new string[] { null });
                }

                var parameters = new Dictionary <string, string>();
                if (messageType != 0)
                {
                    //send
                    var sendResult = Message.SendMessage(type: messageType,
                                                         to: to,
                                                         title: message.Subject,
                                                         body: message.Body,
                                                         parameters: parameters);
                    if (sendResult == "1")
                    {
                        message.Status = 1;
                        result        += "[" + message.ID + "]Sent to " + message.To;
                    }
                    else
                    {
                        message.Status = 2;
                        result        += "[" + message.ID + "]Not send to" + message.To + ". Error: " + sendResult;
                    }
                    entity.SaveChanges();
                }
            }

            return(result);
        }
Пример #4
0
        public IEnumerable <CompanyMaster> GetCustomerList()
        {
            List <CompanyMaster> customerList = new List <CompanyMaster>();
            CompanyMaster        customer;

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                string internalCustomersIds = Digimaker.Config.Custom.AppSettings["InternalCustomers"].ToString(); // "2038,4, 2037,2030";
                var    internalCustIds      = internalCustomersIds.Split(',').ToArray();
                string externalCostumersIds = Digimaker.Config.Custom.AppSettings["ExternalCostumers"].ToString(); //"3039";
                var    externalCustIds      = externalCostumersIds.Split(',').ToArray();

                var internalCustomerList = (from u in entity.OrganizationUnits
                                            where internalCustIds.Contains(u.ParentID.ToString())
                                            select u).ToList();
                var ExternalCustomerList = (from u in entity.OrganizationUnits
                                            where externalCustIds.Contains(u.ParentID.ToString())
                                            select u).ToList();

                foreach (var item in internalCustomerList)
                {
                    customer = new CompanyMaster();
                    if (!string.IsNullOrEmpty(item.Code))
                    {
                        customer.IsMVA = false;
                    }
                    else
                    {
                        customer.IsMVA = true;
                    }
                    customer.IsPrimary            = true;
                    customer.OrganizationUnitId   = item.OrganizationUnitID.ToString();
                    customer.OrganizationUnitName = item.OrganizationUnitName;

                    customerList.Add(customer);
                }
                foreach (var item in ExternalCustomerList)
                {
                    customer           = new CompanyMaster();
                    customer.IsPrimary = false;
                    if (!string.IsNullOrEmpty(item.Code))
                    {
                        customer.IsMVA = false;
                    }
                    else
                    {
                        customer.IsMVA = true;
                    }
                    customer.OrganizationUnitId   = item.OrganizationUnitID.ToString();
                    customer.OrganizationUnitName = item.OrganizationUnitName;
                    customerList.Add(customer);
                }
            }
            return(customerList);
        }
Пример #5
0
        public UserGroupList GetUserGroupList(string userGroupId)
        {
            UserGroupList            userGroup;
            List <UserGroupListUser> personlist;
            UserGroupListUser        person;

            int id = 0;

            if (userGroupId != null)
            {
                id = Convert.ToInt32(userGroupId);
            }
            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                userGroup = new UserGroupList();
                var usrResult = entity.UserGroups.Where(u => u.UserGroupId == id).Select(s => s).FirstOrDefault();
                if (usrResult != null)
                {
                    personlist = new List <UserGroupListUser>();

                    userGroup.userGroupId = usrResult.UserGroupId;
                    userGroup.name        = usrResult.UserGroupName;
                    var persons = entity.People.Join(entity.UserGroup_User, p => p.PersonID, o => o.UserId, (P, O) => new { p = P, o = O })
                                  .Where(w => w.o.UserGroupId == usrResult.UserGroupId).Select(s => s.p).OrderBy(o => o.DisplayName).ToList();
                    if (persons != null)
                    {
                        foreach (var p in persons.Where(p => p.Custom2 == null))
                        {
                            person               = new UserGroupListUser();
                            person.id            = p.PersonID;
                            person.name          = p.DisplayName;
                            person.telephone     = p.MobilePhone;
                            person.UserEmail     = p.Email;
                            person.PositionTitle = p.Title;

                            var comp = entity.OrganizationUnits.Join(entity.OrganizationUnit_Person, ou => ou.OrganizationUnitID, oup => oup.OrganizationUnitID, (OU, OUP) => new { ou = OU, oup = OUP })
                                       .Where(w => w.oup.PersonID == p.PersonID).Select(s => s.ou).FirstOrDefault();
                            if (comp != null)
                            {
                                person.companyId   = comp.OrganizationUnitID;
                                person.companyName = comp.OrganizationUnitName;
                            }


                            personlist.Add(person);
                        }
                    }
                    userGroup.personList = personlist;
                }
            }
            return(userGroup);
        }
Пример #6
0
        public string AddToUserGroupList(UserAssignedGroupModel userGroupModel)
        {
            UserGroup_User _userGroupUsr;
            string         message = "";

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                using (var scope = entity.Database.BeginTransaction())
                {
                    try
                    {
                        var ExistingGrp = entity.UserGroup_User.Where(w => w.UserId == userGroupModel.userId).ToList();
                        if (ExistingGrp != null)
                        {
                            foreach (var item in ExistingGrp)
                            {
                                entity.UserGroup_User.Remove(item);
                                entity.SaveChanges();
                            }
                        }
                        if (userGroupModel.userGroup != null)
                        {
                            foreach (var userGroup in userGroupModel.userGroup)
                            {
                                _userGroupUsr             = new UserGroup_User();
                                _userGroupUsr.UserId      = userGroupModel.userId;
                                _userGroupUsr.UserGroupId = userGroup;
                                entity.UserGroup_User.Add(_userGroupUsr);
                            }
                            entity.SaveChanges();
                            scope.Commit();
                            message = "successfully assigned UserGroup";
                        }
                        else
                        {
                            message = "UserGroup not assigned";
                        }
                    }
                    catch (Exception)
                    {
                        scope.Rollback();
                        message = "";
                    }
                    finally{
                        scope.Dispose();
                    }
                }
            }
            return(message);
        }
        public List <Menu> GetMenuDetail(string menuItemID, int includeArticle = 0)
        {
            var         idList   = menuItemID.Split('-');
            List <Menu> menuList = new List <Menu>();

            foreach (var id in idList)
            {
                int menuId = 0;
                if (menuItemID != null)
                {
                    menuId = Convert.ToInt32(id);
                }

                Menu menu;
                using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
                {
                    menu = new Menu();
                    var result = entity.MenuItems.Where(w => w.MenuItemID == menuId).Select(s => s).FirstOrDefault();
                    menu.MenuId      = result.MenuItemID;
                    menu.MenuName    = result.MenuItemName;
                    menu.MenuDesc    = result.MetaDescription;
                    menu.PicturePath = entity.PictureProperties.Where(w => w.PictureMainID == result.Pictureid).Select(s => s.Filepath).ToString();
                }

                if (includeArticle == 1)
                {
                    var rows = SiteBuilder.Content.Article.ByMenuIds(id, Digimaker.Data.Content.ArticleSortOrder.Default, 0, true, SiteBuilder.Content.Article.ReturnValues.AbstractAndFullstory, 1).Article.Rows;
                    if (rows.Count > 0)
                    {
                        var article      = (Digimaker.Schemas.Web.ArticleViewData.ArticleRow)rows[0];
                        var articleModel = new ArticleModel();
                        articleModel.ArticleDesc = article.Abstract.Replace("{RelatedPersons}", "");
                        articleModel.ArticleName = article.Headline;
                        articleModel.PicturePath = article.Filepath;
                        articleModel.ArticleId   = article.MainID;
                        articleModel.ArticleBody = article.Fullstory;

                        var children = new List <ArticleModel>();
                        children.Add(articleModel);
                        menu.Children = children;
                    }
                }
                menuList.Add(menu);
            }
            return(menuList);
        }
Пример #8
0
        public IEnumerable <UserMaster> GetPersonListByCompany(int customerNo)
        {
            List <UserMaster> um = new List <UserMaster>();

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                var result = entity.OrganizationUnit_Person.Join(entity.People, a => a.PersonID, b => b.PersonID, (A, B) => new { a = A, b = B })
                             .Where(w => w.a.OrganizationUnitID == customerNo).Select(s => s.b).ToList();
                foreach (var item in result)
                {
                    um.Add(new UserMaster {
                        PersonID = item.PersonID, DisplayName = item.DisplayName
                    });
                }
            }
            return(um);
        }
Пример #9
0
        public OrgUnit GetCustomerCompanyDetail(string orgId)
        {
            int id = 0;

            if (orgId != null)
            {
                id = Convert.ToInt32(orgId);
            }
            OrgUnit orgUnit;
            List <OrganizationPerson> personlist;
            OrganizationPerson        person;

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                var orgResult = entity.OrganizationUnits.Where(w => w.OrganizationUnitID == id).Select(s => s).FirstOrDefault();
                personlist   = new List <OrganizationPerson>();
                orgUnit      = new OrgUnit();
                orgUnit.id   = orgResult.OrganizationUnitID;
                orgUnit.name = orgResult.OrganizationUnitName;
                orgUnit.Code = string.IsNullOrEmpty(orgResult.Code)?true :false;
                orgUnit.OrganizationNumber = orgResult.OrgNumber;
                if (orgResult.PictureID != null)
                {
                    orgUnit.PicturePath = entity.PictureProperties.Where(w => w.PicturePropertyID == orgResult.PictureID).SingleOrDefault().Filepath.ToString();
                }
                var persons = entity.People.Join(entity.OrganizationUnit_Person, p => p.PersonID, o => o.PersonID, (P, O) => new { p = P, o = O })
                              .Where(w => w.o.OrganizationUnitID == orgResult.OrganizationUnitID).Select(s => s.p).OrderBy(o => o.DisplayName).ToList();
                if (persons != null)
                {
                    foreach (var p in persons.Where(p => p.Custom2 == null))
                    {
                        person            = new OrganizationPerson();
                        person.id         = p.PersonID;
                        person.name       = p.DisplayName;
                        person.telephone  = p.MobilePhone;
                        person.UserEmail  = p.Email;
                        person.Department = p.Custom1;
                        person.UserGroup  = string.Join(",", entity.UserGroups.Join(entity.UserGroup_User, gp => gp.UserGroupId, go => go.UserGroupId, (GP, GO) => new { gp = GP, go = GO })
                                                        .Where(w => w.go.UserId == p.PersonID).Select(gs => gs.gp.UserGroupName));
                        personlist.Add(person);
                    }
                }
                orgUnit.personList = personlist;
            }
            return(orgUnit);
        }
        public async Task <ApiResponse> UpdateClean(int OrderNo)
        {
            this.CheckAccess();
            ApiResponse response = new ApiResponse();
            var         rsp      = await orderAsync(OrderNo);

            if (rsp.errorType == 1)
            {
                return(rsp);
            }
            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                using (var dbContextTransaction = entity.Database.BeginTransaction())
                {
                    try
                    {
                        var query =
                            from ord in entity.BookingDetails
                            where ord.BookingID == OrderNo
                            select ord;

                        // Execute the query, and change the column values
                        // you want to change.
                        foreach (var ord in query)
                        {
                            ord.IsClean = true;
                            // Insert any additional changes to column values.
                        }
                        entity.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();

                        response.message   = ex.Message;
                        response.errorType = (int)Enums.ErrorType.Error;
                        return(response);
                    }
                }
            }
            response.message   = "Successfully Clean";
            response.errorType = (int)Enums.ErrorType.Success;
            return(response);
        }
Пример #11
0
        public IEnumerable <UserGroupList> GetUserGroup()
        {
            List <UserGroupList> userGroupList;
            UserGroupList        userGroup;

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                var usrResult = entity.UserGroups.Select(s => s).ToList();
                userGroupList = new List <UserGroupList>();
                foreach (var usr in usrResult)
                {
                    userGroup             = new UserGroupList();
                    userGroup.userGroupId = usr.UserGroupId;
                    userGroup.name        = usr.UserGroupName;
                    userGroupList.Add(userGroup);
                }
            }
            return(userGroupList);
        }
Пример #12
0
        public string DeleteUserGroup(int userGroupId)
        {
            string message = "";

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                //For multiple records
                var allRec = entity.UserGroup_User.Where(w => w.UserGroupId == userGroupId);
                entity.UserGroup_User.RemoveRange(allRec);
                //For Single record
                var singleRec = entity.UserGroups.FirstOrDefault(x => x.UserGroupId == userGroupId);// object your want to delete
                entity.UserGroups.Remove(singleRec);

                entity.SaveChanges();
                message = "Delete Successfully";
            }

            return(message);
        }
Пример #13
0
        public IEnumerable <UserGroupList> UserWiseGroupList(int userId)
        {
            List <UserGroupList> userGroupList;
            UserGroupList        userGroup;

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                var usrResult = entity.UserGroups.Join(entity.UserGroup_User, p => p.UserGroupId, o => o.UserGroupId, (P, O) => new { p = P, o = O })
                                .Where(w => w.o.UserId == userId).Select(s => s.p).OrderBy(o => o.UserGroupName).ToList();
                userGroupList = new List <UserGroupList>();
                foreach (var usr in usrResult)
                {
                    userGroup             = new UserGroupList();
                    userGroup.userGroupId = usr.UserGroupId;
                    userGroup.name        = usr.UserGroupName;
                    userGroupList.Add(userGroup);
                }
            }
            return(userGroupList);
        }
        public IHttpActionResult GetChildMenuList(int parentMenuId)
        {
            ApiResponse response = new ApiResponse();

            if (parentMenuId != 0)
            {
                using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
                {
                    var result = entity.MenuItems.Where(w => w.Parentid == parentMenuId).Select(s => s).ToList();
                    if (result.Count > 0)
                    {
                        List <MenuItems> menulist = new List <MenuItems>();
                        MenuItems        menu;
                        foreach (var item in result)
                        {
                            menu            = new MenuItems();
                            menu.MenuItemID = item.MenuItemID;
                            menu.MenuName   = item.MenuItemName;
                            menulist.Add(menu);
                        }

                        return(Ok(menulist));
                    }
                    else
                    {
                        response.message   = "No data found";
                        response.errorType = (int)ErrorType.Error;
                        return(Ok(response));
                    }
                }
            }
            else
            {
                response.message   = "please enter valid menuid";
                response.errorType = (int)ErrorType.Error;
                return(Ok(response));
            }
        }
 public int GetKitchenDepID(int buildingid)
 {
     try
     {
         using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
         {
             string KitchenDepID = entity.MenuItems.Where(w => w.MenuItemID == buildingid).Select(s => s.MetaDescription).FirstOrDefault();
             if (!string.IsNullOrEmpty(KitchenDepID))
             {
                 if (KitchenDepID.IndexOf('=') > 0)
                 {
                     string DepID = KitchenDepID.Substring(KitchenDepID.IndexOf('=') + 1, KitchenDepID.Length - (KitchenDepID.IndexOf('=') + 1));
                     return(Convert.ToInt32(DepID));
                 }
             }
         }
     }
     catch (Exception e)
     {
         return(0);
     }
     return(0);
 }
        public List <KitchenNotification> GetKitchenNotification(int buildingid)
        {
            DateTime TodayDate = System.DateTime.Now.Date;
            List <KitchenNotification> kitchenNotificationList = new List <KitchenNotification>();
            KitchenNotification        kitchenNotification;

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                var notDeliveredCount = entity.BookingDetails.Where(ord => ord.BuildingID == buildingid && DbFunctions.TruncateTime(ord.FromDate) <= TodayDate && ord.IsClean == false && ord.IsDeliver == false && ord.BookingServiceLists.Count(s => s.IsKitchen == true && s.Status == false) > 0).GroupBy(info => DbFunctions.TruncateTime(info.FromDate)).Select(group => new { FromDate = DbFunctions.TruncateTime(group.Key), NotDeliveredCount = group.Count(), NotClearUpCount = 0 }).OrderBy(x => DbFunctions.TruncateTime(x.FromDate));
                var notClearUpCount   = entity.BookingDetails.Where(ord => ord.BuildingID == buildingid && DbFunctions.TruncateTime(ord.FromDate) <= TodayDate && ord.IsClean == false && ord.IsDeliver == true && ord.BookingServiceLists.Count(s => s.IsKitchen == true && s.Status == false) > 0).GroupBy(info => DbFunctions.TruncateTime(info.FromDate)).Select(group => new { FromDate = DbFunctions.TruncateTime(group.Key), NotDeliveredCount = 0, NotClearUpCount = group.Count() }).OrderBy(x => DbFunctions.TruncateTime(x.FromDate));

                var result  = notDeliveredCount.Union(notClearUpCount);
                var groupby = result.GroupBy(info => DbFunctions.TruncateTime(info.FromDate)).Select(group => new { FromDate = DbFunctions.TruncateTime(group.Key), NotDeliveredCount = group.Sum(x => x.NotDeliveredCount), NotClearUpCount = group.Sum(x => x.NotClearUpCount) }).OrderBy(x => DbFunctions.TruncateTime(x.FromDate));
                foreach (var line in groupby)
                {
                    kitchenNotification                   = new KitchenNotification();
                    kitchenNotification.Fromdate          = line.FromDate;
                    kitchenNotification.NotDeliveredCount = line.NotDeliveredCount;
                    kitchenNotification.NotClearUpCount   = line.NotClearUpCount;
                    kitchenNotificationList.Add(kitchenNotification);
                }
            }
            return(kitchenNotificationList);
        }
Пример #17
0
        public string DeleteUserGroupList(int userGroupId, int userId)
        {
            string message = "";

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                //For Single record
                var singleRec = entity.UserGroup_User.FirstOrDefault(x => x.UserGroupId == userGroupId && x.UserId == userId); // object your want to delete

                if (singleRec != null)
                {
                    entity.UserGroup_User.Remove(singleRec);

                    entity.SaveChanges();
                    message = "Delete Successfully";
                }
                else
                {
                    message = "Delete Unsuccessfully";
                }
            }

            return(message);
        }
Пример #18
0
        public IEnumerable <UserMaster> GetPersonList(int OrgUnitId)
        {
            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                //if( UserAccess.SelfOnly() )
                //{
                //    _persons = SiteBuilder.Content.Person.ByPersonId( Digimaker.User.Identity.ID, true );
                //}
                //else
                //{
                _persons = SiteBuilder.Content.Person.ByOrgUnitId(OrgUnitId, true, true);
                //  }


                for (int i = 0; i < _persons.Person.Count; i++)
                {
                    if (string.IsNullOrEmpty(_persons.Person[i]["Custom2"] == DBNull.Value ? string.Empty :_persons.Person[i]["Custom2"].ToString()))
                    {
                        //string orgUnitName = string.Empty;
                        //string orgUnitId = string.Empty;
                        //bool isPrimary = false;
                        //bool flag = false;
                        //Digimaker.Schemas.Web.PersonViewData.OrganizationUnit_PersonRow[] orgs = _persons.Person[i].GetOrganizationUnit_PersonRows();
                        //if (orgs.Length > 0)
                        //{
                        //    orgUnitName = orgs[0].OrganizationUnitName.ToString();
                        //    orgUnitId = orgs[0].OrganizationUnitId.ToString();
                        //    if (orgUnitId != null)
                        //    {
                        //        int orgUId = Convert.ToInt32(orgUnitId);
                        //        int OrgParentId = Convert.ToInt32(entity.OrganizationUnits.Where(w => w.OrganizationUnitID == orgUId).Select(s => s.ParentID).FirstOrDefault());

                        //        // internal Customers
                        //        string internalCustomersIds = Digimaker.Config.Custom.AppSettings["InternalCustomers"].ToString(); // "2038,4, 2037,2030";
                        //        List<int> internalCustIds = internalCustomersIds.Split(',').Select(int.Parse).ToList();
                        //        if (internalCustIds.Contains(OrgParentId))
                        //        {
                        //            isPrimary = true;
                        //            flag = true;
                        //        }

                        //        // external Costumers
                        //        string externalCostumersIds = Digimaker.Config.Custom.AppSettings["ExternalCostumers"].ToString(); //"3039";
                        //        List<int> externalCustIds = externalCostumersIds.Split(',').Select(int.Parse).ToList();
                        //        if (externalCustIds.Contains(OrgParentId))
                        //        {
                        //            isPrimary = false;
                        //            flag = true;
                        //        }
                        //    }

                        //}
                        //if (flag) {
                        userMaster.Add(new UserMaster {
                            PersonID = Convert.ToInt32(_persons.Person[i].PersonId), GivenName = _persons.Person[i].GivenName.ToString(), FamilyName = _persons.Person[i].FamilyName.ToString(), DisplayName = _persons.Person[i].DisplayName.ToString()
                        });
                        // }
                    }
                }
            }
            return(userMaster);
        }
        public async Task <ApiResponse> orderAsync(int OrderNo)
        {
            ApiResponse response = new ApiResponse();

            using (var session = new TripletexSession())
            {
                try
                {
                    var consumerKey    = Digimaker.Config.Custom.AppSettings["consumerKey"].ToString();
                    var employeeKey    = Digimaker.Config.Custom.AppSettings["employeeKey"].ToString();
                    var customerNumber = Digimaker.Config.Custom.AppSettings["CustomerNo"].ToString();
                    // var productNumber = CloudConfigurationManager.GetSetting("TripletexProductNumber");

                    if (await session.CreateSessionToken(consumerKey, employeeKey))
                    {
                        using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
                        {
                            //// check the Product Number
                            var resfood1 = from ord in entity.BookingServiceLists where ord.BookingID == OrderNo && ord.IsKitchen == true && ord.Status == false select ord;
                            foreach (var it in resfood1)
                            {
                                if (it.ArticleId != "0")
                                {
                                    var product1 = await session.GetProductFromNumberChecking(it.ArticleId, "id", "name", "vatType(id)", "priceExcludingVatCurrency");

                                    if (product1 == 0)
                                    {
                                        response.message   = "Article id does not exist in Tripletex, article id :-" + it.ArticleId;
                                        response.errorType = (int)Enums.ErrorType.Error;
                                        return(response);
                                    }
                                }
                            }
                            ////

                            var customerNo = entity.BookingDetails.Where(w => w.BookingID == OrderNo).Select(s => s).FirstOrDefault();
                            // 14008116
                            //var customer = await session.GetCustomerFromCustomerNo((int)customerNo.Customer, "id", "name");
                            var customer = await session.GetCustomerFromCustomerNo(Convert.ToInt32(customerNumber), "id", "name");

                            if (customer != null)
                            {
                                var order = new JObject();
                                order["orderDate"]    = ((DateTime)customerNo.FromDate).ToString("yyyy-MM-dd"); // "2019-04-25";
                                order["deliveryDate"] = ((DateTime)customerNo.FromDate).ToString("yyyy-MM-dd");
                                order["customer"]     = JObject.FromObject(new { id = customer["id"] });
                                order["reference"]    = "BookingID: " + customerNo.BookingID.ToString();
                                int departmentid = GetKitchenDepID(Convert.ToInt32(customerNo.BuildingID));
                                if (departmentid > 0)
                                {
                                    var department = await session.GetdepartmentFromNumber(departmentid.ToString(), "id");

                                    order["department"] = JObject.FromObject(new { id = department["id"] });
                                }
                                var rsp = await session.CreateOrder(order);

                                // product
                                //// food list
                                var resfood = from ord in entity.BookingServiceLists where ord.BookingID == OrderNo && ord.IsKitchen == true && ord.Status == false select ord;
                                foreach (var it in resfood)
                                {
                                    var orderLine = new JObject();
                                    if (it.ArticleId != "0")
                                    {
                                        var product = await session.GetProductFromNumber(it.ArticleId, "id", "name", "vatType(id)", "priceExcludingVatCurrency");

                                        if (product != null)
                                        {
                                            orderLine["product"] = JObject.FromObject(new { id = product["id"] });
                                            orderLine["vatType"] = JObject.FromObject(new { id = product["vatType"]["id"] });
                                            orderLine["unitPriceExcludingVatCurrency"] = it.CostPrice;
                                            orderLine["count"] = it.Qty;
                                        }
                                    }
                                    orderLine["description"] = it.Tekst;
                                    orderLine["order"]       = JObject.FromObject(rsp);
                                    var rsp1 = await session.CreateOrderLine(orderLine);
                                }
                            }
                        }


                        //            try
                        //            {
                        //               // var invoice = await session.CreateInvoice(order["id"].Value<int>(), lastDayOfMonth);
                        //                //log.Info($"Created and sent invoice {invoice["invoiceNumber"]}");
                        //                //return invoice;
                        //            }
                        //            catch (Exception e)
                        //            {
                        //               // log.Error($"Could not create invoice of order {order["orderNumber"]}");
                        //            }
                    }
                    else
                    {
                        response.message = await session.CreateSessionTokenCheck(consumerKey, employeeKey);

                        response.errorType = (int)Enums.ErrorType.Error;
                        return(response);
                    }
                }
                catch (Exception e)
                {
                    response.message   = e.Message;
                    response.errorType = (int)Enums.ErrorType.Error;
                    return(response);
                }
                finally
                {
                    await session.DestroySessionToken();
                }
            }
            response.message   = "Successfully order";
            response.errorType = (int)Enums.ErrorType.Success;
            return(response);
        }
        public KitchenDisplay GetKitchenDisplay(DateTime TodayDate, int buildingid)
        {
            this.CheckAccess();
            DateTime       TodayDate1     = TodayDate.Date;// System.DateTime.Now.Date;
            KitchenDisplay kitchenDisplay = new KitchenDisplay();


            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                // Food Not Cleaned List
                List <FoodNotCleanedList> notcleanedList = new List <FoodNotCleanedList>();
                FoodNotCleanedList        notclean;
                var result = from ord in entity.BookingDetails
                             where ord.BuildingID == buildingid && DbFunctions.TruncateTime(ord.FromDate) == TodayDate1 && ord.IsClean == false && ord.IsDeliver == true && ord.BookingServiceLists.Count(s => s.IsKitchen == true) > 0
                             select ord;

                foreach (var item in result)
                {
                    notclean = new FoodNotCleanedList();
                    //string text = entity.BookingServiceLists.Where(w => w.BookingID == item.BookingID && w.IsMainService == true).Select(s => s.Tekst).FirstOrDefault();
                    string text = entity.Articles.Where(w => w.MainID == item.ServiceID && w.Status == 0).Select(s => s.Headline).FirstOrDefault();
                    notclean.OrderNo    = item.BookingID;
                    notclean.Text       = text + " " + item.BookingName;
                    notclean.Todate     = item.ToDate;
                    notclean.Fromdate   = item.FromDate;
                    notclean.NoOFPeople = item.NoOfPeople;
                    notcleanedList.Add(notclean);
                }
                kitchenDisplay.FoodNotCleanedList = notcleanedList;

                // Food Not Delivered List
                List <FoodNotDeliveredList> notdeliveredList = new List <FoodNotDeliveredList>();
                FoodNotDeliveredList        notdelivered;
                FoodList food;
                var      res = from ord in entity.BookingDetails
                               where ord.BuildingID == buildingid && DbFunctions.TruncateTime(ord.FromDate) == TodayDate1 && ord.IsClean == false && ord.IsDeliver == false && ord.BookingServiceLists.Count(s => s.IsKitchen == true) > 0
                               select ord;
                foreach (var item in res)
                {
                    notdelivered = new FoodNotDeliveredList();
                    List <FoodList> foodList = new List <FoodList>();
                    //string text = entity.BookingServiceLists.Where(w => w.BookingID == item.BookingID && w.IsMainService == true).Select(s => s.Tekst).FirstOrDefault();
                    string text = entity.Articles.Where(w => w.MainID == item.ServiceID && w.Status == 0).Select(s => s.Headline).FirstOrDefault();
                    notdelivered.OrderNo    = item.BookingID;
                    notdelivered.Text       = text + " " + item.BookingName;
                    notdelivered.Todate     = item.ToDate;
                    notdelivered.Fromdate   = item.FromDate;
                    notdelivered.NoOFPeople = item.NoOfPeople;

                    //// food list
                    var resfood = from ord in entity.BookingServiceLists
                                  where ord.BookingID == item.BookingID && ord.IsKitchen == true && ord.Status == false
                                  select ord;
                    bool isFoodservice = false;
                    foreach (var it in resfood)
                    {
                        food             = new FoodList();
                        food.Text        = it.Tekst;
                        food.Quantity    = it.Qty;
                        food.DeliverTime = it.Time;
                        foodList.Add(food);
                        isFoodservice = true;
                    }
                    if (isFoodservice)
                    {
                        notdelivered.FoodList = foodList;
                        notdeliveredList.Add(notdelivered);
                    }
                }
                kitchenDisplay.FoodNotDeliveredList = notdeliveredList;
            }
            return(kitchenDisplay);
        }
Пример #21
0
        public IEnumerable <OrganizationPerson> UserListbyBuilding(int buildingId, int orgId)
        {
            List <OrganizationPerson> userList = new List <OrganizationPerson>();
            OrganizationPerson        user;

            using (BraathenEiendomEntities entity = new BraathenEiendomEntities())
            {
                if (buildingId != 0)
                {
                    var orgList = entity.OrganizationUnits.Where(w => w.ParentID == buildingId).Select(s => new { s.OrganizationUnitID, s.OrganizationUnitName }).ToList();
                    if (orgList != null)
                    {
                        foreach (var item in orgList)
                        {
                            var persons = entity.People.Join(entity.OrganizationUnit_Person, p => p.PersonID, o => o.PersonID, (P, O) => new { p = P, o = O })
                                          .Where(w => w.o.OrganizationUnitID == item.OrganizationUnitID).Select(s => s.p).OrderBy(o => o.DisplayName).ToList();
                            if (persons != null)
                            {
                                foreach (var p in persons.Where(p => p.Custom2 == null || p.Custom2 == ""))
                                {
                                    user            = new OrganizationPerson();
                                    user.id         = p.PersonID;
                                    user.name       = p.DisplayName;
                                    user.telephone  = p.MobilePhone;
                                    user.UserEmail  = p.Email;
                                    user.Department = p.Custom1;
                                    user.UserGroup  = string.Join(",", entity.UserGroups.Join(entity.UserGroup_User, gp => gp.UserGroupId, go => go.UserGroupId, (GP, GO) => new { gp = GP, go = GO })
                                                                  .Where(w => w.go.UserId == p.PersonID).Select(gs => gs.gp.UserGroupName));
                                    user.OrganizationName = item.OrganizationUnitName;
                                    userList.Add(user);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (orgId != 0)
                    {
                        var persons = entity.People.Join(entity.OrganizationUnit_Person, p => p.PersonID, o => o.PersonID, (P, O) => new { p = P, o = O })
                                      .Where(w => w.o.OrganizationUnitID == orgId).Select(s => s.p).OrderBy(o => o.DisplayName).ToList();
                        if (persons != null)
                        {
                            foreach (var p in persons.Where(p => p.Custom2 == null || p.Custom2 == ""))
                            {
                                user            = new OrganizationPerson();
                                user.id         = p.PersonID;
                                user.name       = p.DisplayName;
                                user.telephone  = p.MobilePhone;
                                user.UserEmail  = p.Email;
                                user.Department = p.Custom1;
                                user.UserGroup  = string.Join(",", entity.UserGroups.Join(entity.UserGroup_User, gp => gp.UserGroupId, go => go.UserGroupId, (GP, GO) => new { gp = GP, go = GO })
                                                              .Where(w => w.go.UserId == p.PersonID).Select(gs => gs.gp.UserGroupName));
                                userList.Add(user);
                            }
                        }
                    }
                }
            }
            userList = userList.OrderBy(o => o.name).ToList();
            return(userList);
        }