/// <summary> /// Performs the location Save. /// </summary> /// <param name="parentLocationId">The LocationId</param> /// <param name="newLocationName">The location name.</param> /// <returns></returns> public void SaveLocation(int?locationId, string newLocationName, int userId, int companyId, bool isAddNew = true) { if (!isAddNew) { //update existing location Data.Location locaton = GetLocation(locationId.Value); if (locaton != null) { locaton.LocationName = newLocationName; locaton.LastUpdatedByUserId = userId; locaton.LastUpdatedDate = Utils.Now; } } else { //Insert a new location Data.Location location = new Data.Location() { LocationName = newLocationName, CompanyId = companyId, ParentLocationId = locationId, CreatedByUserId = userId, CreatedDate = Utils.Now, LastUpdatedByUserId = userId, LastUpdatedDate = Utils.Now, IsActive = true }; DataContext.Locations.AddObject(location); } DataContext.SaveChanges(); }
/// <summary> /// Deletes the locaton. /// </summary> /// <param name="location">The location.</param> /// <param name="userId">The user identifier.</param> public void DeleteLocaton(Data.Location location, int userId) { InventoryBL inventoryBL = new InventoryBL(DataContext); location.IsActive = false; location.LastUpdatedByUserId = userId; location.LastUpdatedDate = Utils.Now; if (!location.ParentLocationId.HasValue) { List <CompanyUserRole> locationUserRoles = inventoryBL.GetInventoryRolesByLocationId(location.LocationId); foreach (CompanyUserRole locationUserRole in locationUserRoles) { locationUserRole.IsActive = false; } } DataContext.SaveChanges(); }
public void Decode(byte[] array) { reader = new KrosmagaReader(); reader.SetData(array); int tag; while (reader.B.BaseStream.Position < reader.B.BaseStream.Length && (tag = reader.ReadTag()) != 0) { if (tag <= 88) { if (tag <= 40) { if (tag <= 18) { if (tag != 8) { if (tag == 18) { Data.GameEvent gameEvent = new Data.GameEvent(); int size = (int)reader.ReadRawVarint32(); gameEvent.Decode(reader.ReadMessage(size)); TriggeredEvents.Add(gameEvent); continue; } } else { EventType = (Enums.EventType)Enum.Parse(typeof(Enums.EventType), reader.ReadRawVarint32().ToString()); continue; } } else { if (tag == 24) { RelatedCardInstance = (int)reader.ReadRawVarint32(); continue; } if (tag == 32) { RelatedTradingCardId = (int)reader.ReadRawVarint32(); continue; } if (tag == 40) { Triggerer = (int)reader.ReadRawVarint32(); continue; } } } else if (tag <= 64) { if (tag == 48) { Int1 = (int)reader.ReadRawVarint32(); continue; } if (tag == 56) { Int2 = (int)reader.ReadRawVarint32(); continue; } if (tag == 64) { Int3 = (int)reader.ReadRawVarint32(); continue; } } else { if (tag == 72) { Int4 = (int)reader.ReadRawVarint32(); continue; } if (tag == 80) { Int5 = (int)reader.ReadRawVarint32(); continue; } if (tag == 88) { Bool1 = reader.ReadBool(); continue; } } } else if (tag <= 138) { if (tag <= 114) { if (tag == 96) { Bool2 = reader.ReadBool(); continue; } if (tag == 104) { UInt1 = reader.ReadRawVarint32(); continue; } if (tag == 114) { Data.Location location = new Data.Location(); int size = (int)reader.ReadRawVarint32(); location.Decode(reader.ReadMessage(size)); Location1 = location; continue; } } else { if (tag == 122) { Data.Location location = new Data.Location(); int size = (int)reader.ReadRawVarint32(); location.Decode(reader.ReadMessage(size)); Location2 = location; continue; } if (tag == 130) { Data.ValueModification valueModification = new Data.ValueModification(); int size = (int)reader.ReadRawVarint32(); valueModification.Decode(reader.ReadMessage(size)); ValueModification1 = valueModification; continue; } if (tag == 138) { Data.ValueModification valueModification = new Data.ValueModification(); int size = (int)reader.ReadRawVarint32(); valueModification.Decode(reader.ReadMessage(size)); ValueModification2 = valueModification; continue; } } } else if (tag <= 160) { if (tag == 146) { Data.CellCoord cellCoord = new Data.CellCoord(); int size = (int)reader.ReadRawVarint32(); cellCoord.Decode(reader.ReadMessage(size)); CellCoord1 = cellCoord; continue; } if (tag == 154) { Data.CellCoord cellCoord = new Data.CellCoord(); int size = (int)reader.ReadRawVarint32(); cellCoord.Decode(reader.ReadMessage(size)); CellCoord2 = cellCoord; continue; } if (tag == 160) { MovementType = (Enums.MovementType)Enum.Parse(typeof(Enums.MovementType), reader.ReadRawVarint32().ToString()); continue; } } else { if (tag == 168) { SInt1 = reader.DecodeZigZag32(reader.ReadRawVarint32()); continue; } if (tag == 178) { String1 = reader.ReadString(); continue; } if (tag == 184) { TriggerableCapacityType1 = (Enums.TriggerableCapacityType)Enum.Parse(typeof(Enums.TriggerableCapacityType), reader.ReadRawVarint32().ToString()); continue; } } } }
public LocationEventArgs(Data.Location lc) { Location = lc; }
/// <summary> /// Handles the Click event of the btnBulkUpdate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnBulkUpdate_Click(object sender, EventArgs e) { if (!PageBase.StopProcessing) { if (this.Page.IsValid) { if (this.GetBL <CompanyBL>().HasEditPermissionForInventoryStaff(this.CompanyId, UserID, sbInventoryLocations.SelectedLocationId)) { int? locationId = sbInventoryLocations.SelectedLocationId; Data.Code userVisibilityLevel = GetBL <InventoryBL>().GetUserInventoryVisibilityLevel(this.CompanyId, UserID, sbInventoryLocations.SelectedLocationId, false); if (locationId.HasValue) { Data.Location location = GetBL <LocationBL>().GetLocation(locationId.Value); if (location == null) { popupInventoryLocationDeleted.ShowPopup(); sbInventoryLocations.SelectedLocationId = null; upnlBulkUpdate.Update(); return; } } lblToLocation.Text = Utils.ReverseEllipsize(GetBL <LocationBL>().GetLocationPath(locationId, this.CompanyId), 25); string[] itemIdStrings = hdnBulkUpdateSelectedItems.Value.Split(Delimiter.ToCharArray()); bool hasChanges = false; foreach (string itemIdString in itemIdStrings) { int itemId = 0; if (int.TryParse(itemIdString, out itemId) && itemId > 0) { Data.Item item = GetBL <InventoryBL>().GetItem(itemId); if (item != null && item.CompanyId.Value == this.CompanyId && item.Code.SortOrder >= userVisibilityLevel.SortOrder) { item.LocationId = locationId; hasChanges = true; } } } if (hasChanges) { GetBL <InventoryBL>().SaveChanges(); } if (InformCompanyInventoryToReloadBulkUpdate != null) { InformCompanyInventoryToReloadBulkUpdate(); } ScriptManager.RegisterStartupScript(this.Page, GetType(), "ShowSavedMessage", "showNotification('" + bulkUpdateSavedNotice.ClientID + "', 5000);", true); LoadData(); } else { if (OnInformCompanyInventoryToShowErrorPopup != null) { OnInformCompanyInventoryToShowErrorPopup(ErrorCodes.NoEditPermissionForInventory); } } } } }
public Data.Location GetLocation(PizzaStoreDBContext dbContext, int favLocID) { Data.Location locationName = dbContext.Location.First(u => u.Id == favLocID); return(locationName); }
/// <summary> /// Saves the item details. /// </summary> /// <param name="itemDetails">The item details.</param> /// <param name="skipConcurrencyCheck">if set to <c>true</c> [skip concurrency check].</param> /// <param name="shouldCommit">if set to <c>true</c> [should commit].</param> /// <returns></returns> public ItemResultObject SaveItemDetails(ItemDetails itemDetails, bool skipConcurrencyCheck = false, bool shouldCommit = false) { ItemResultObject itemResultObject = new ItemResultObject(); ItemBriefBL itemBriefBL = new ItemBriefBL(DataContext); InventoryBL inventoryBL = new InventoryBL(DataContext); ProjectBL projectBL = new ProjectBL(DataContext); LocationBL locationBL = new LocationBL(DataContext); CompanyBL companyBL = new CompanyBL(DataContext); int itemId = itemDetails.ItemId; int companyId = 0; int projectId = 0; Data.ItemBrief itemBrief = itemBriefBL.GetItemBrief(itemDetails.ItemBriefId); Data.Item item = inventoryBL.GetItem(itemId); if (itemDetails.ItemId > 0) { companyId = item.CompanyId.Value; } else if (itemBrief != null && item == null) { companyId = itemBrief.Project.CompanyId; projectId = itemBrief.ProjectId; item = new Item(); item.CompanyId = companyId; } bool isInventoryPage = itemDetails.RelatedTable == "Company"; string relatedTable = "Company"; int relatedId = companyId; if (itemDetails.RelatedTable == "Project" && projectId > 0) { relatedTable = itemDetails.RelatedTable; relatedId = projectId; } if (!projectBL.ShouldStopProcessing(relatedTable, relatedId, itemDetails.UserId)) { ErrorCodes errorCode; if (itemDetails.ItemBriefId > 0 && !inventoryBL.CanEditIteminItemBrief(itemDetails.ItemBriefId, itemDetails.ItemId)) { itemResultObject.Status = "CONCURRENCY"; itemResultObject.ErrorCode = (int)ErrorCodes.NoEditPermissionForItemInItemBrief; itemResultObject.Message = "No Write Permission"; return(itemResultObject); } else if (relatedTable == "Company" && itemId > 0 && inventoryBL.CheckPermissionsForItemDetailsPage(itemDetails.UserId, itemId, companyId, out errorCode, false) == null) { itemResultObject.Status = "CONCURRENCY"; itemResultObject.ErrorCode = (int)errorCode; itemResultObject.Message = "No Write Permission"; return(itemResultObject); } else if (!skipConcurrencyCheck && itemId > 0 && itemDetails.LastUpdatedDate != item.LastUpdatedDate) { itemResultObject.Status = "NOTOK"; itemResultObject.Message = "Can not update"; return(itemResultObject); } item.Name = itemDetails.Name; item.Description = itemDetails.Description; if (itemDetails.IsEditableToAdminOnly && item.Quantity != itemDetails.Quantity)//Commit if changes exist { bool canSaveQty = true; if (item.Quantity > itemDetails.Quantity)//Only when reduces Units { int maxBookedQty = inventoryBL.GetMaxBookedQuantityForAllDuration(itemDetails.ItemId); if (maxBookedQty > itemDetails.Quantity) { canSaveQty = false; } } if (canSaveQty) { item.Quantity = itemDetails.Quantity; } else { itemResultObject.Status = "CONCURRENCY"; itemResultObject.ErrorCode = (int)ErrorCodes.QuantityUpdateFailed; itemResultObject.Message = "Can not reduce quantity"; return(itemResultObject); } } item.LastUpdatedByUserId = itemDetails.UserId; item.LastUpdatedDate = Utils.Now; if (isInventoryPage) { if (companyBL.HasEditPermissionForInventoryStaff(companyId, itemDetails.UserId, itemDetails.LocationId)) { item.CreatedFor = itemDetails.CreatedFor; if (itemDetails.LocationId.HasValue) { Data.Location location = locationBL.GetLocation(itemDetails.LocationId.Value); if (location == null) { itemResultObject.Status = "CONCURRENCY"; itemResultObject.ErrorCode = (int)ErrorCodes.InventoryLocationDeleted; itemResultObject.Message = "Item Location not available"; return(itemResultObject); } } item.LocationId = itemDetails.LocationId; } else { itemResultObject.Status = "CONCURRENCY"; itemResultObject.ErrorCode = (int)ErrorCodes.NoEditPermissionForInventory; itemResultObject.Message = "No Edit Permission For Item In Inventory"; return(itemResultObject); } } if (itemDetails.ItemTypeId.HasValue) { item.ItemTypeId = itemDetails.ItemTypeId; } //Update ItemBooking if (itemBrief != null) { ItemBooking itemBooking = inventoryBL.GetItemBookingByItemID(itemId, itemBrief.ItemBriefId, "ItemBrief"); itemBooking.Quantity = itemDetails.Quantity.Value; itemBooking.LastUpdateDate = Utils.Now; itemBooking.LastUpdatedBy = itemDetails.UserId; } if (itemDetails.ItemValues != null) { foreach (ValuesInfo iValue in itemDetails.ItemValues) { if (iValue.Id == 0) { //It is an Insert ItemValue iValueNew = new ItemValue(); iValueNew.ItemId = item.ItemId; iValueNew.FieldId = iValue.FieldId; iValueNew.Value = iValue.Value; iValueNew.FieldOptionId = iValue.FieldOptionId; DataContext.ItemValues.AddObject(iValueNew); } else { //Update ItemValue itemValue = GetItemFieldValueById(iValue.Id); if (itemValue != null) { if (iValue.Value == string.Empty && iValue.FieldOptionId == null) { DataContext.ItemValues.DeleteObject(itemValue); } else { itemValue.FieldOptionId = iValue.FieldOptionId; itemValue.Value = iValue.Value; } } } } } if (shouldCommit) { DataContext.SaveChanges(); } itemResultObject.Status = "OK"; return(itemResultObject); } else { itemResultObject.Status = "STOPPROCESS"; return(itemResultObject); } }
/// <summary> /// Invites the inventory users. /// </summary> public void InviteInventoryUsers() { bool isInventoryAdmin = Utils.IsCompanyInventoryAdmin(this.CompanyId, UserID); CompanyUserRole highestRole = GetBL <InventoryBL>().GetHighestInventoryRole(this.CompanyId, UserID); bool hasStaffMemberPermission = isInventoryAdmin || (highestRole != null && highestRole.Code.SortOrder <= Utils.GetCodeByValue("CompanyUserTypeCode", "INVSTAFF").SortOrder); if (isInventoryAdmin || GetBL <InventoryBL>().IsCompanyLocationManagerAnyLocation(this.CompanyId, UserID)) { HideNotifications(); Invitation pendingInvitation = null; User user = null; if (SelectedUserId > 0) { user = this.GetBL <PersonalBL>().GetUser(SelectedUserId); //Check whether this user already has a pending invitation. pendingInvitation = GetPendingInvitationForUser(user); } else { pendingInvitation = GetPendingInvitationForEmail(SelectedUserEmail); } if (pendingInvitation != null) { //This scenario can only occur if the user accidentaly double clicks the send button. //So the popup is silently closed without doing anything. divSearchResults.Visible = false; //ucUserInvitationPopup.HideInivitePopup(); popupInviteProjectMember.HidePopup(); } else { string toUserFullName = txtInventoryUserName.Text.Trim(); string toEmail = SelectedUserEmail; string fromUserFullName = (Support.UserFirstName + " " + Support.UserLastName).Trim(); string fromUserEmail = GetBL <PersonalBL>().GetUser(this.UserID).Email1; string companyName = GetBL <CompanyBL>().GetCompany(this.CompanyId).CompanyName; #region Create and save Invitation object Invitation invitation = new Invitation(); DataContext.Invitations.AddObject(invitation); invitation.FromUserId = UserID; if (SelectedUserId > 0) { invitation.ToUserId = SelectedUserId; invitation.ToEmail = user.Email1; } else { invitation.ToName = toUserFullName; invitation.ToEmail = SelectedUserEmail; } invitation.InvitationTypeCodeId = GetInvitationTypeCodeId(ViewMode.InventoryTeam); invitation.InvitationStatusCodeId = Support.GetCodeIdByCodeValue("InvitationStatus", "PENDING"); invitation.RelatedTable = StageBitz.Common.Constants.GlobalConstants.RelatedTables.UserRoleTypes.Companies; invitation.RelatedId = CompanyId; invitation.CreatedByUserId = invitation.LastUpdatedByUserId = UserID; invitation.CreatedDate = invitation.LastUpdatedDate = Now; StringBuilder sbInviteInventoryStaffEmail = new StringBuilder(); StringBuilder sbInviteInventoryObserverEmail = new StringBuilder(); string staffHtml = string.Empty; string observerHtml = string.Empty; string allNoAcessHtml = string.Empty; Dictionary <int, int> locationRoles = sbInventoryLocationRoles.LocationPermissions; if (locationRoles.Count == 0) { popupInviteInventoryUsers.HidePopup(); if (isInventoryAdmin) { PageBase.ShowErrorPopup(ErrorCodes.InventoryLocationDeleted); } else { if (OnInformCompanyInventoryToShowErrorPopup != null) { OnInformCompanyInventoryToShowErrorPopup(ErrorCodes.NoEditPermissionForInventory, true); } } return; } foreach (int locationId in locationRoles.Keys) { if (Utils.HasLocationManagerPermission(this.CompanyId, this.UserID, locationId)) { int userTypeCodeId = locationRoles[locationId]; invitation.InvitationUserRoles.Add( new InvitationUserRole { CreatedByUserId = UserID, CreatedDate = Now, IsActive = true, LastUpdatedByUserId = UserID, LastUpdatedDate = Now, UserTypeCodeId = userTypeCodeId, LocationId = locationId } ); Data.Location location = GetBL <LocationBL>().GetLocation(locationId); Code inventoryStaffCode = Utils.GetCodeByValue("CompanyUserTypeCode", "INVSTAFF"); Code inventoryObserverCode = Utils.GetCodeByValue("CompanyUserTypeCode", "INVOBSERVER"); if (userTypeCodeId == inventoryStaffCode.CodeId) { sbInviteInventoryStaffEmail.Append(string.Format("<li>{0}</li>", location.LocationName)); } else if (userTypeCodeId == inventoryObserverCode.CodeId) { sbInviteInventoryObserverEmail.Append(string.Format("<li>{0}</li>", location.LocationName)); } } else { if (OnInformCompanyInventoryToShowErrorPopup != null) { popupInviteInventoryUsers.HidePopup(); OnInformCompanyInventoryToShowErrorPopup(ErrorCodes.NoEditPermissionForInventory, !hasStaffMemberPermission); } return; } } if (sbInviteInventoryStaffEmail.Length > 0) { staffHtml = string.Format(@"<p>You have been invited as Inventory Staff for the following location(s):</p> <ul> {0} </ul> <div style='margin-left:25px;'><p>This means that for this location:</p> <ul> <li>You can now view all the bookings for your Inventory</li> <li>You can create, edit and delete inventory Items</li> <li>And you can still make your own bookings.</li> </ul></div>", sbInviteInventoryStaffEmail.ToString()); } if (sbInviteInventoryObserverEmail.Length > 0) { observerHtml = string.Format(@"<p>You have been invited as Inventory Observer for the following location(s):</p> <ul> {0} </ul> <div style='margin-left:25px;'><p>This means that for this location:</p> <ul> <li>You’ll be able to browse their Inventory</li> <li>You can request Items from it for your own bookings.</li> </ul></div>", sbInviteInventoryObserverEmail.ToString()); } if (sbInviteInventoryObserverEmail.Length == 0 && sbInviteInventoryStaffEmail.Length == 0) { allNoAcessHtml = @"<p>You'll have Inventory Observer access to Items listed against the default Inventory location for @CompanyName. This means that you'll be able to browse these Items and also request these Items for your own bookings</p>"; } DataContext.SaveChanges(); #endregion Create and save Invitation object if (SelectedUserId > 0) { toEmail = user.Email1; string dashboardUrl = string.Format("{0}/Default.aspx", StageBitzUrl); //For Non registered users First need to activate the account if (!user.IsActive) { dashboardUrl = string.Format("{0}/Public/Invitation.aspx?invitationCode={1}", StageBitzUrl, HttpServerUtility.UrlTokenEncode(Utils.EncryptStringAES(invitation.InvitationId.ToString()))); } EmailSender.StageBitzUrl = StageBitzUrl; EmailSender.InviteInventoryUserExistingUser(toEmail, user.FirstName, fromUserFullName, fromUserEmail, companyName, dashboardUrl, staffHtml, observerHtml, allNoAcessHtml); divInviteSent.InnerText = string.Format("{0} ({1}) has been invited to the Company Inventory.", Support.TruncateString(toUserFullName, 50), toEmail); } else { string invitationCode = HttpServerUtility.UrlTokenEncode(Utils.EncryptStringAES(invitation.InvitationId.ToString())); string invitationUrl = string.Format("{0}/Public/Invitation.aspx?invitationCode={1}", StageBitzUrl, invitationCode); StageBitz.Common.EmailSender.StageBitzUrl = StageBitzUrl; EmailSender.InviteInventoryUserNewUser(toEmail, toUserFullName, fromUserFullName, fromUserEmail, companyName, invitationUrl, staffHtml, observerHtml, allNoAcessHtml); divInviteSent.InnerText = string.Format("{0} ({1}) has been invited to the Company Inventory.", Support.TruncateString(toUserFullName, 50), toEmail); } divInviteSent.Visible = true; divSearchResults.Visible = false; popupInviteInventoryUsers.HidePopup(); } if (InvitationSent != null) { InvitationSent(this, EventArgs.Empty); } } else { if (OnInformCompanyInventoryToShowErrorPopup != null) { popupInviteInventoryUsers.HidePopup(); OnInformCompanyInventoryToShowErrorPopup(ErrorCodes.NoEditPermissionForInventory, !hasStaffMemberPermission); } } }